ASP.NET MVC 3 Refresh

For those action type which derive from ActionResult

Name Result
ContentResult String literal
EmptyResult None
FileContentResult/
FilePathResult/
FileStreamResult
Contents of a file
HttpUnauthorizedResult HTTP 403
JavaScriptResult Script to execute
JsonResult JSON format
RedirectResult Redirects to a new URL
RedirectToRouteResult Redirect to another action
ViewResult/
PartialViewResult
View

Use ActionName attribute to give action an alias name.

Use AcceptVerbs attribute to define action(“Httpverbs.Post” or "Httpverbs.HttpGet”)

Action Filters

Name Result
Authorize Only allow authorized users or roles
HandleError When unhandled exception occurred, specify a view
OutputCache Cache the output
ValidateInput Turn off request validation
ValidateAntiForgeryToken Prevent cross site request

If you need something to be executed when any action was triggered, create a new customize attribute and derive from ActionFilterAttribute.

The ActionFilter could be put to Golbal.asax file to make it global, so this way could avoid to put it everywhere in the code.

Switch from C# mode to HTML in Razor: Use TEXT tag or “@:”.

Use ChildActionOnly attribute to stop user to invoke the action from URL and gain the benefit from PartialView at the same time.

Happy Coding Everyday~ 快乐编码,享受生活~
原文地址:https://www.cnblogs.com/tedzhang/p/3102113.html