What is MVC
- A MVC is an architectural pattern which separates the business logic and User interface.
- It is broadly classified into three parts
- Model:It is a business entity which is used to represent application data and provides the data to view.
- View:It is responsible for look and feel and views are generated as per model properties.
- Controller:It is responsible to take end user request,handles the user input data and loads an appropriate view and model.
What is difference between Html.Textbox and Html.Textboxfor in MVC
- Html.Textbox is not a strongly typed and it does not requires a View.we can hardcore the values.
- Html.Textboxfor is a strongly typed and it requires a View model.
What is Routing in MVC
- Routing engine uses the Route table to match the incoming request URL pattern against the pattern defined in the Route table.
- If any pattern matches with the route table then it forwards the request to the particular controller and the controller action method.
- We can specify one or more url pattern to the route table with in the Register route method present in Application start event iii Global.asax file.
How can we restrict MVC actions to be invoked by Get or post methods
- We can decorate the controller action method by "HttpGet" or "Httppost" attribute to restrict the type of Http calls.
- Both are used to pass the data from controller to view but the difference between them is
- Viewbag is a dynamic property where as viewdata is a dictionary object.
- Boxing and unboxing happens in View data where as it does not happens in Viewbag.
- View bag performance will be high when compared to View data.
Does Tempdata preserves the data in Next request also
- Tempdata is available for the current request and for the subsequent request it is available based on the whether the temp data value is read or not.
- If the temp data value is read then it will not be available for the subsequent request.
What is Partial view in MVC
- Partial view is similar to User control in ASP.Net.
- Partial view is also called as a reusable view as it is rendered inside any other view.
- Partial views can be reside in a shared folder or a specific view folder.
- If we add a view to a shared folder then it is available for the entire application but if we add a view to a specific view folder then it is available for that view itself.
Difference between Partial and Render partial
- Render partial returns void and the output will be written directly to the Response stream where as Partial returns "MVCHtmlString" which can be assigned to a variable and manipulate it when required.
- If we want to change the output then we make use of Partial else Render partial.
- Render partial performance will be fast as it writes the output directly to the Response stream.
What is the use of Peek and Keep in Tempdata
- Tempdata will be persistant based on the Four conditions which are shown below
- Not Read:If the Tempdata value is not read then the value of tempdata will be persistant for the Subsequent request.
- Normal Read:If we read the value of the Tempdata then the Tempdata value will not be persistent for the subsequent request.
- Read and Keep:If we read the Tempdata and if we call Keep method then the Tempdata will be persistent.
- Peek and Read:If we read the Tempdata by using Peek method then the Tempdata value will be persistent for the Next request.
How can we enable Data Annotation validation on Client side
- It is a Two step process to enable validation on Client side
- First we need to set ClientValidationenabled and Unobstrusivejavascriptenabled to true in config file.
- Second we need to add Javascript files which are listed below
- jquery.1.7.1.min.js
- jquery.Validate.min.js
- jquery.Validate.unobstrusive.min.js
When to use ViewResult
- If a controller action method make sure returns a View then we make use of View Result or else we make use of Sub types present in Action result.
What is difference between UpdateModel and Tryupdatemodel
- UpdateModel will throws an exception if any validation fails but for Tryupdatemodel it will not throws an exception but it returns a Bool value indication whether validation gets Succeed or not.
Can we overload a MVC action methods
- Yes we can overload two action methods with same name.If we run directly we will get an ambiguity error.In order to solve the problem we make use of ActionName attribute which will solve the problem.
What are Layout in MVC
- Layout are very much similar to Master page in Asp.net whicl allows us to maintain a consistent look and behaviour for Multiple views.
How to enable and disable Optimization in MVC
- To enable or disable optimization we need to write the below code in Application start event which is present in Global.asax file
- system.web.optimization.BundleTable.EnableOptimizations=false;
Explain the Concept of Scaffolding
- Scaffolding allows us to generate the CRUD(Create,Read,Update and delete) code and we can change the code as per our requirement.
- Scaffolding uses Entity framework internally.
How to call one Actionmethod in a controller to another action method in the same controller
- To call action method with in the same controller we make use of below code
- return RedirectToAction("Action Name");
- To call an action method which is present in another controller we make use of below code
- return RedirectToAction("Action name","Controller Name");
What are Non Action methods in MVC
- In MVC all methods which are present in controller are treated as Actions.So if we have a method in controller and if we don't want to use it as an action method then we need to decorate a method with "NonAction" attribute.
What is Viewstart page in MVC
- In content pages or views we make use of Layout in many other views and if we want to use another Layout file we need to change the existing layout which we have used it in another views which is a Time consuming process
- In order to overcome we make use of Viewstart file and will use layout property in Viewstart file and refer this file in other views.So if we make any changes in Viewstart will automatically get reflected in all otheer views.
Can a view be shared across multiple controllers
- Yes we can share a view across multiple controllers by placing the view in Shared folder.
In MVC which action filter executes first and which executes last
- In MVC Authentication filter will executes first and the Exception filter executes last.
What is the difference between Asp.net wenforms and MVC
ASP.Net web forms
|
MVC
|
| It consists of Web server controls to design UI. | It consists of Html helpers to design UI. |
| It has state management techniques. | It does not contains automatic state management techniques. |
| It has a file based Url means filename exists in the url.File name should be available in the web server where an application is hosted. | It has a route based url means controller name and controller action method will be present in route table and will be invoked when end user sends an incoming request |
| It has a master page for consistent feel and look. | It consists of Layout for consistent feel and look. |
| It has an user controls for re usability. | It consists of partial views for Re usability.. |
| No SOC(Separation of concern) as .aspx page is tightly coupled. | It has SOC which separates views and controller |
What are Hidden Input and Read only in MVC
- Hidden Input:It is used when we don't want the end user to see or edit the property but ihe value of the property must be post to server when the form is submitted.Then we make use of Hidden Input attribute.
- Read Only:It allows us to make the property read only but we can change the property value on the View.But when we post the form to web server model binder will treat the property as read only and will not change the value of the property.
How to change the Action name in MVC
- "ActionName" attribute allows us to change the controller action name.
What is a Child Actionin MVC
- An action method which is decorated with ChildActiononly is called as Child action.
- These child methods does not respond to Url request.If we invoke a method using url then it will get a compile error.
- it can be rendered using @Html.Action("Method name");
No comments:
Post a Comment