MVC无法从代码到html页面获取值
本文关键字:获取 html 代码 MVC | 更新日期: 2023-09-27 17:49:21
我试图从c#到MVC文本框的值。但是它不能在HTML中显示。
我使用了以下代码:
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);
cshtml中的代码如下:
@Html.EditorFor(up => up.CompileOutput, new{style = "width:100px; height:50px; "})
如果你发布模型到控制器,然后在控制器中更改模型,在视图中它将显示你先发布的,发布的数据具有更高的优先级。您可以尝试清除modelstate
ModelState.Clear();