开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜