How to display the text in MVC?

走远了吗. 提交于 2019-12-20 03:17:26

问题


I want to display the error message in a textbox in MVC. I used following code for that but its not displaying.

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

@Html.EditorFor(up => up.CompileOutput)
return View(userProgram);

In the above code userProgram returns the value for CompileOutput. But its not displaying in the textbox.


回答1:


Just try it,

ModelState.Clear();



回答2:


why don't you try this to show textbox

@Html.TextBoxFor(up => up.CompileOutput)



回答3:


If CompileOutput is a string you could use the following:

@Html.TextBoxFor(up => up.CompileOutput)

If it is a complex object you need to define the EditorTemplate for that type.




回答4:


add this row top of view page.

@model YourNamespace.yourModel

and change this

@Html.EditorFor(model => model.CompileOutput)


来源:https://stackoverflow.com/questions/22298640/how-to-display-the-text-in-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!