Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do you get and set the value in TextBox using MVC?
Posted
Comments
vinodkumarnie 9-Sep-14 8:23am    
Format your question properly. using which way you want get and set, using javascript or Jquery or in cshtml file or what...?
Nathan Minier 9-Sep-14 8:32am    
MVC is also a design pattern and not a technology. Might want to tag it with the language or framework that you're using as well then,
Christian Amado 10-Sep-14 11:03am    
Imrpove your question in order to help you.
Ranjeet Patel 11-Sep-14 7:14am    
did you just put a question here and forget about to come back and look for the answer..?

1 solution

In MVC, we use View Model to bind the values to the view like I am using Razor view engine syntax below:-
C#
@Html.TextBoxFor(m=>m.ValueForTextBox) //Binded the value to the textbox model and passed
@Html.ValidationFor(m=>m.ValueForTextBox) //If any validation is applied

//On the Server side:-
public ActionResult GetValueForTextBox()
{
    var viewModel = new ValueForTextBoxViewModel
     {
         ValueForTextbox = "Fetch and assign the value here"      
     }
    return View(viewModel);
}

//ViewModel goes below:
public class ValueForTextBoxViewModel
{
    [Required("Required Field")] //Validation Message
    public string ValueForTextbox {get; set;}
}


Hope this helps anyway
Thanks
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900