1 What are the Main Razor Syntax Rules?
Answer
C# Example
Learn more here – Introduction to Microsoft ASP.NET MVC 3 Razor View Engine
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
HTML Links
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.
ASP Syntax
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
2) What does Model-View-Controller represent in an MVC application?
4 What is the use of remote validation in MVC?
Answer
Remote validation is the process where we validate specific data posting data to a server without posting the entire form data to the server. Lets see an actual scenario, in one of my projects I had a requirement to validate an email address, whetehr it already exists in the database. Remote validation was useful for that; without posting all the data we can validate only the email address supplied by the user.
Practical Explanation
Lets create a MVC project and name it accordingly, for me its “TestingRemoteValidation”. Once the project is created lets create a model named UserModel that will look like:
Lets get some understanding of the remote attribute used, so the very first parameter “CheckExistingEmail” is the the name of the action. The second parameter “Home” is referred to as controller so to validate the input for the UserEmailAddress the “CheckExistingEmail” action of the “Home” controller is called and the third parameter is the error message. Lets implement the “CheckExistingEmail” action result in our home controller.
Learn more here – Remote Validation in MVC