ASP.NET MVC Quick Notes
December 21st, 2009.Filed under Programming.
I have been working with ASP.NET MVC since it`s first public release for MSDN developers. I would like to write down some quick notes that can be helpful.
In a master page do not use a traditional link styled line, use rather < %= Page.ResolveUrl(" ~/Stylesheet/main.css ") % > inside a link url
Sending data to model via View( data ) and getting it back as foreach ( var dataObject in Model ) but remember to cast it !
RedirectToAction(“Index”,”Home”); “MethodName”, “ControlName”, using ActionResult as return type.
< %= Html.ActionLink("Delete", "DeleteUser", new { id = user.ID}) % >
creating an HTML < a > element that links to another action method on a Controller The first parameter to the Html.ActionLink() helper method is the link-text to display (in this case Delete), the second parameter is the Controller action name we want to generate the link to
(in this case the DeleteUser), and the third parameter is a set of parameters to send to the action
(implemented as an anonymous type with property name/values). In this case we are specifying the
“id” parameter of the User we want to delete/link to, and because the default URL routing rule in ASP.NET
MVC is “{Controller}/{Action}/{id}” the Html.ActionLink() helper method.
Control methods with parameters on submit getting LINQ Object from user ! It has to fulfill all LINQ Object values !
Like a normal form submitting a new person, and you have a LINQ person class, well the information you are getting in as a Person Object has to be filled.
ViewData[ "YourData" ] = “Object, List, Array…etc”;
[ AcceptVerbs( HttpVerbs.Get ) ] && [ AcceptVerbs( HttpVerbs.Post ) ] // On same method and I love this one !
Html.Encode(“HTML STRING”) -> < % = to < % : –> without the method
