Hriskesh Ashokan
Hriskesh Ashokan

Reputation: 781

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? Your help is appreciated!

Upvotes: 0

Views: 867

Answers (1)

Paul
Paul

Reputation: 1509

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.

Upvotes: 1

Related Questions