c# - MVC无法从代码到html页面获取值

标签 c# asp.net-mvc html-helper

我正在尝试从 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/

相关文章:

javascript - JSON.stringify 更改日期

asp.net-mvc - Html.TextBoxFor 的源代码在哪里

asp.net-mvc - 如何在 MVC 中使用 HtmlHelper 获取自定义 id 进行渲染

c# - 更改 CookieDomain 后 FormsAuthentication.SignOut() 不工作

c# - 使用 Linq Grouping 如何按特定组排序然后剩余组降序

c# - 从硬编码模型到数据驱动菜单

asp.net-mvc - 使用外部不记名 token (MVC4 Web Api) 登录 Facebook

jquery - 从 ajax 发布 MVC Razor 表单

c# - 如何在 NRules 中进行最佳写入规则定义

c# - 代码执行是如何进入这个 'if' 语句的?