declare label in mvc
I have a label called "test" in my Index.asp page in my MVC view folder. I want to be able to change the value of it in my controller class. Can someone explain how it can be achieved? You开发者_JAVA技巧r help is appreciated!
Quickest way, but there are better options depending on what you want to do:
CONTROLLER
public ActionResult Index()
{
ViewData["testValue"] = "new label value";
return View();
}
INDEX VIEW - ACCESS THE VALUE LIKE THIS:
<label for="test"><%= ViewData["testValue"] %></label>
If you use form view models, you can set the display name in the class, and then use the html helpers to generate your form items, which will automatically create your labels based on what you have set them to be.
精彩评论