Balaji Kondalrayal
Balaji Kondalrayal

Reputation: 1751

MVC cannot get the value from code to html page

I am trying to get the value from the C# to MVC textbox. But its not displaying in HTML.

I used the following code:

foreach (CompilerError CompErr in results.Errors)
            {

                userProgram.CompileOutput = "Line number " + CompErr.Line +
                             ", Error Number: " + CompErr.ErrorNumber +
                             ", '" + CompErr.ErrorText + ";" +
                             Environment.NewLine + Environment.NewLine;
                output = userProgram.CompileOutput;
            }

var model = new UserProgram()
        {
            CompileOutput = output
        };
        return View(model);

The following code is in cshtml:

@Html.EditorFor(up => up.CompileOutput, new{style = "width:100px; height:50px; "})

Upvotes: 2

Views: 163

Answers (1)

x2.
x2.

Reputation: 9668

If you post model to controller, and then change model in controller, in view it will display what you posted first, posted data has higher priority. You can try to clear modelstate

ModelState.Clear();

Upvotes: 3

Related Questions