2

I did the comments tutorial on http://reactjs.net/getting-started/tutorial.html and got it to render server side using .net mvc.

I have an existing mvc app where I rewrote a page in react. I'm trying to render it server side but get this message:

"'System.Web.Mvc.HtmlHelper>' does not contain a definition for 'React' and no extension method 'React' " - the error refers to the "@Html.React" code in my view.

@Html.React("TopicAnswers", new
{
    initialAnswers = Model,
    url = Url.Action("TopicAnswers", new { id = ViewBag.TopicID }),
})

I have the same files downloaded from Nuget as the tutorial. I tried this at the top of my view to no avail:

@using React;

In my ReactConfig.cs file, I see a "using React;" at the top and in the code, this is fine:

ReactSiteConfiguration.Configuration
                .AddScript("~/Scripts/internal/eusVote/TopicAnswers.jsx");

One more thing. My view is in /Areas/Subfolder/Views

Why does my code complain about @Html.React in my view?

2
  • 4
    try to add namespace in web.config which is located in Views folder Commented May 20, 2015 at 5:49
  • @SnakeEyes Awesome. I added React.Web.MVC namespace to the respective web.config in the Views folder and that did it. Actually got another error but at least this part is resolved. You guys are amazing. Muchos gracias. - BTW, the reason it wasn't working was because the view was in an Areas subfolder and not the main View folder. Thus, I had to add namespace to the "internal" web.config. Thanks again ! Commented May 20, 2015 at 6:26

4 Answers 4

2

Make sure to put following using statement in your View

using System.Web.Optimization.React;
Sign up to request clarification or add additional context in comments.

Comments

1

Add this using statement for React MVC in your view:

@using React.Web.Mvc

Comments

0

In MVC Core 2.1 this helper extension is now within React.AspNet:

@using React.AspNet;

Comments

0

Add

<add namespace="React.Web.Mvc" />

to your Web.config in your View folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.