简体   繁体   English

如何区分行动结果

[英]How to differentiate between actionresults

My page load action result and http post action result both pass in the model. 我的页面加载操作结果和http post动作结果都传递给模型。

    [Authorize]
    public ActionResult StepTwo(PostcodesModel model)
    {
        return View();
    }

    [Authorize]
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult StepTwo(PostcodesModel model)
    {
        return View();
    }

Since they both take in the model, what can I add to make them unique ? 既然他们都参与了模型,我可以添加什么来使它们独一无二?

You should use ActionName attribute, it represents an attribute that is used for the name of an action. 您应该使用ActionName属性,它表示用于操作名称的属性。 If it is not present the name of the method is used. 如果不存在,则使用方法的名称。

    [Authorize]
    public ActionResult StepTwo(PostcodesModel model)
    {
        return View();
    }

    [ActionName("StepTwo")]
    [Authorize]
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult StepTwoPost(PostcodesModel model)
    {
        return View();
    }

I usually use FormCollection : 我通常使用FormCollection

[Authorize]
public ActionResult StepTwo(PostcodesModel model)
{
    return View();
}

[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult StepTwo(PostcodesModel model, FormCollection additionalData)
{
    return View();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM