Pls, explain this line (Am confused)
ASP.NET MVC also provides the ability to pass strongly typed data or objects to a view template.
What is Strongly Typed Data?
:)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Alok SaxenaPosted Aug 20, 2014, 3:53 AM
Strongly Typed Data is a type tied to Object and Object's properties.
Step-1 Controller
public class DepartmentController : Controller
{
private DepartmentDBContext db = new DepartmentDBContext();
public ActionResult Index()
{
return View(db.Department.ToList());
}
}
Step-2 View
Details
Department Name
@Html.DisplayNameFor(model => model.DepartmentTitle)
Ramesh MaruthiPosted Aug 11, 2014, 3:47 PM
Def2 :A Strongly Typed view means it has a ViewModel associated to it that the controller is passing to it and all the elements in that View can use those ViewModel properties
You can have strongly typed partials as well. Meaning that piece of Html needs specific data so you type it to a certain ViewModel
Here is an example of a Strongly Typed View
@model SomeViewModel
...// all the html comes after
A view that is strongly typed have a @model SomeViewModel line
Here's one that renders a strongly typed View
public ActionResult Index() {
var model = new SomeViewModel();
return View(model);
}
And the view makes use of that ViewModel by having the @model SomeViewModel at the top of the file.
So now that the view has a ViewModel I can display elements that are bound to the ViewModel like
@Model.Name
@Model.Location
OR for Controls------
@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Location)
you can find the brief explanation in that links :)
Abhishek JaiswalPosted Aug 11, 2014, 3:40 PM
the above mentioned line is from the heading u did added in ur reply. :D
i just want explanation of that line in brief.
:)
Ramesh MaruthiPosted Aug 11, 2014, 10:13 AM
http://blog.stevensanderson.com/2008/02/21/aspnet-mvc-making-strongly-typed-viewpages-more-easily/
http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/strongly-typed-views-in-mvc/
In this link once look at from this heading
Strongly Typed Models and the @model Keyword
http://www.asp.net/mvc/tutorials/mvc-5/introduction/accessing-your-models-data-from-a-controllerRick explained in a detail way :)