Articles → ASP .NET MVC → Model In Asp.Net MVC
Model In Asp.Net MVC
Purpose
Example
- Create a model class
- Create a property and a method inside the model class.
- Create a strongly type view.
- Call the method created in the model.
- Bind data with a textbox.
Create A Model Class
public class TestModel {
}
Create A Property And A Method Inside The Model Class
public class TestModel {
public string TestProperty {
get;
set;
}
public string GetSomething() {
return "Test";
}
}
Create A Strongly Type View
Click to Enlarge
public ActionResult Test() {
ViewBag.Message = "Your app description page.";
return View();
}
Call The Method Created In The Model
public ActionResult Test() {
TestModel model = new TestModel();
model.TestProperty = model.GetSomething();
ViewBag.Message = "Your app description page.";
return View(model);
}
Bind Data With A Textbox
@model MvcApplication1.Models.TestModel
@{
ViewBag.Title = "Test";
}
@Html.TextBoxFor(x => x.TestProperty)
Click to Enlarge