Here first we see how to see the view of the ActionMethod
Returning view from action method public ViewReslt Output()
return View();
View(); ---- is used to show the view of the action method
Returning model to view from ActionMethod, We have two methods to return model to view from Action Method
First Scenario Using Object Action method public ActionResult OutputViewWithModel()
{
UserNamePasswordModel model=new UserNamePasswordModel();
model.UserName="user";
model.Password="password";
return View(model);
}
View Code
To retrive it in view code we use
UserName=@Model.UserName
Password=@Model.Password
Second Scenario Using collection of objects ActionMethod public ActionResult OutputWithViewModel()
{
List <UserNamePasswordModel> list=new List<UserNamePasswordModel>list();
return View(list);
}
ViewCode
@foreach(var item in model)
<p>@item.UserName</p>