.NET MVC5 topics (some of the features and precautions before and after the end of the interactive controller)

/// once a HttpGet HttpPost
/// MVC how to identify it? Not depend on parameter identification (source parameters too unstable)
/// must be identified by HttpVerbs,
/// If there is no flag, then the method for identifying the name
/// [ChildActionOnly] Action can not be used to specify the individual request, the request can only be a sub
/// [Bind] to specify which fields to receive only from the front, the other not, prevent additional data submitted
/// [ValidateAntiForgeryToken] anti-duplicate submissions, with a key in a cookie, when submitted the first check

[AcceptVerbs(HttpVerbs.Put | HttpVerbs.Post)] //[HttpPost]
//[HttpPost]
//[HttpGet]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ProductId, CategoryId, Title, Price, Url, ImageUrl")]JDCommodity commodity)
{
    string title1 = this.HttpContext.Request.Params["title"];
    string title2 = this.HttpContext.Request.QueryString["title"];
    string title3 = this.HttpContext.Request.Form["title"];
    if (ModelState.IsValid)//数据校验
    {
        JDCommodity newCommodity = this._iCommodityService.Insert(commodity);
        return RedirectToAction("Index");
    }
    else
    {
        throw new Exception("ModelState未通过检测");
    }
}
Published 147 original articles · won praise 121 · Views 5114

Guess you like

Origin blog.csdn.net/weixin_41181778/article/details/103950278