我正在尝试从 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; "})
最佳答案
如果您将模型发布到 Controller ,然后在 Controller 中更改模型, View 中将显示您先发布的内容,发布的数据具有更高的优先级。您可以尝试清除模型状态
ModelState.Clear();
关于c# - MVC无法从代码到html页面获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22316974/