4

Index.cshtml

@{
  ViewBag.Title = "Home Page";
 }

<div id="content"></div>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.min.js"></script>
<script src="~/Scripts/react/react.min.js"></script>
<script src="@Url.Content("~/Scripts/app/app.jsx")"></script>

app.jsx

var HelloWorld = React.createClass({
    render: function () {
        return (
            <div>Hello World!!</div>
        );
}
});

getting error in browser like

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

1
  • 1
    start your app in debug mode and see what exception it gives you Commented Nov 19, 2017 at 10:09

4 Answers 4

4

Resolved this issue with following steps,

1) Make a sure installed React.Web.Mvc4 Package, it is named in NuGet manager as ReactJS.NET

2) Install the following packages from NuGet manager,

 JavaScriptEngineSwitcher.V8
 JavaScriptEngineSwitcher.V8.Native.win-x64
 JavaScriptEngineSwitcher.V8.Native.win-x86 

3) In App_Start directory update a file ReactConfig.cs

    public static void Configure()
    {
        JsEngineSwitcher.Current.DefaultEngineName = V8JsEngine.EngineName;
        JsEngineSwitcher.Current.EngineFactories.AddV8();
    }

4) Clean, Build the solution.

Sign up to request clarification or add additional context in comments.

Comments

2

First, your code seems to be ok.

You can look at the url that give you error 500 on the browser. localhost/.../.jsx

you may have something like this

Error

If you looks at https://reactjs.net/getting-started/aspnet.html

Install those NuGet

On your project you must have reactconfig.cs

reactconfig.cs file

you need to configurare as in the picture

reactconfig

that's it.

1 Comment

I only configured as follows: JsEngineSwitcher.Current.DefaultEngineName = V8JsEngine.EngineName; JsEngineSwitcher.Current.EngineFactories.AddV8(); I did not add the .AddScript("~/Scripts/bla/bla") and the MVC Razor view finds and renders the jsx file.
0

Try to transpile your .jsx files to .js with babel or web compiler (install from VS extensions) and reference those from the view. Also, remove the second react lib:

<script src="~/Scripts/react/react.min.js"></script>

Comments

0

Resolved by adding this to ConfigureServices in Startup.cs:

services.AddJsEngineSwitcher(options => 
     {
           options.DefaultEngineName = V8JsEngine.EngineName;
           options.EngineFactories.AddV8();
     }
);

Comments

Your Answer

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