asp.net mvc - Create and assign value back from View bag to Text box in MVC -


I have to create a text box in a view-back property in MVC; I like the mapping such as @ Html.TextBox ("comments "Can I View (String) ViewBag.Comments?) But when the page is posted on the server then how can I read it? This viewbag property is not filling back. I am very new to MVC so Probably the concept is not understood.

Thank you

Your webpage wont updates with your view and it's up to you There is no way to get data from the form. Instead, you should use a firmly typed model binding to read your data from your action method or you can check the key in your form data, I am showing examples for both of you:

Example 1: Highly typed model binding.

  [HTTP post] Public Fighter My Action (String Comments) {// Text Box. See Return (); }   

Example 2: Reading from posted data:

  [HTTP post] Public commentary MyAction () {// comment string comments from text box = Request.form ["comments"]; See Return (); }   

I hope you would like to use Example 1.

However, the best practice would be to bind your view with an ideal class and use the HtmlHelper to create a text box such as:

Html.EditorFor (model = & gt; model.Comments)

Where in your model class the comments are property named.

And your action method should accept the same model type as argument. Here's an example:

  [http post] Public ActionCurlutMyAction (MyMold Model) {string comments = model.Comments; }   

And you should bind MyModel with your visual type model.

I can understand that, as you are new to MVC, it can not be clear now, therefore, I would suggest to look at some basic MVC tutorials. You can start from here:

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -