Reputation: 1984
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?
Upvotes: 2
Views: 5448
Reputation: 1
Add
<add namespace="React.Web.Mvc" />
to your Web.config in your View folder.
Upvotes: 0
Reputation: 152
In MVC Core 2.1 this helper extension is now within React.AspNet:
@using React.AspNet;
Upvotes: 0
Reputation: 194
Add this using statement for React MVC in your view:
@using React.Web.Mvc
Upvotes: 1
Reputation: 177
Make sure to put following using statement in your View
using System.Web.Optimization.React;
Upvotes: 2