1 What are HTML helpers in MVC?
With MVC, HTML helpers are much like traditional ASP.NET Web Form controls.
Just like web form controls in ASP.NET, HTML helpers are used to modify HTML. But HTML helpers are more lightweight. Unlike Web Form controls, an HTML helper does not have an event model and a view state.
In most cases, an HTML helper is just a method that returns a string.
With MVC, you can create your own helpers, or use the built in HTML helpers.
Standard HTML Helpers
The easiest way to render an HTML link in is to use the HTML.ActionLink() helper.With MVC, the Html.ActionLink() does not link to a view. It creates a link to a controller action.
The first parameter is the link text, and the second parameter is the name of the controller action.
The Html.ActionLink() helper above, outputs the following HTML:
The Html.ActionLink() helper has several properties:
HTML Form Elements
There following HTML helpers can be used to render (modify and output) HTML form elements:
ASP.NET Syntax C#
Learn more here – HTML Helpers in MVC: Part 1
1 What are the Main Razor Syntax Rules?
Learn more here – Introduction to Microsoft ASP.NET MVC 3 Razor View Engine
3 How can we done Custom Error Page in MVC?
The HandleErrorAttribute allows you to use a custom page for this error. First you need to update your web.config file to allow your application to handle custom errors.
Then, your action method needs to be marked with the atttribute.
By calling the ThrowException action, this would then redirect the user to the default error page. In our case though, we want to use a custom error page and redirect the user there instead.So, lets create our new custom view page.
Next, we simply need to update the HandleErrorAttribute on the action method.
Learn more here – Custom Error Page in ASP.NET MVC
Define POST and GET action types.
POST action type submits data to be processed to a specified resource. We pass the essential URL and data with all the POST requests. It can take up overloads.
GET action type requests data from a specified resource. We pass the compulsory URLs with all the GET requests. It can take up overloads.Â
Can you tell two instances where routing is not required or implemented?
We do not require routing when routing is disabled for a URL pattern and when a physical file matching the URL pattern is found.Â
2 What is Route Constraints in MVC?
Routing is a great feature of MVC, it provides a REST based URL that is very easy to remember and improves page ranking in search engines.
This article is not an introduction to Routing in MVC, but we will learn a few features of routing and by implementing them we can develop a very flexible and user-friendly application. So, lets start without wasting valuable time.
Add constraint to URL
This is very necessary for when we want to add a specific constraint to our URL. Say, for example we want a URL.
So, we want to set some constraint string after our host name. Fine, lets see how to implement it.
Its very simple to implement, just open the RouteConfig.cs file and you will find the routing definition in that. And modify the routing entry as in the following. We will see that we have added “abc” before.
Controller name, now when we browse we need to specify the string in the URL, as in the following:
Learn more here – Route Constraints in MVC