1

I am just new to MVC.

when we use "@Html.EditorFor" in razor view, it generates textbox.

My requirement is that I need to supply some value from viewbag or session to user's in that textbox?

Is it possible and if yes how can i do?

OR

What are the alternatives?

1 Answer 1

2

In your action method in the controller, pre-load a model with some data:

public ActionResult Index()
{
    MyModel model = new MyModel();
    model.FirstName = "Bob";
    model.LastName = "Hoskins";

    return View(model);
}

Then make your View strongly typed. These pre-set values should now appear on your view. You probably want to populate them from a service layer or resource file, rather than have them as hardcoded strings like my example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.