繁体   English   中英

如何集成两个具有相同actionresult名称的[HttpPost]? (MVC)

[英]How to integrate two [HttpPost] with the same actionresult name? (MVC)

我想做的事:

使用两个httpPost操作结果,现在它们具有相同的名称(索引)..但是当我更改其中一个的名称并运行代码时,没有任何反应。 我应该如何修改我的代码,以便运行所有动作结果?

       [HttpPost]
    public async Task<ActionResult> Index(HttpPostedFileBase photo)
    {
        ViewBag.hello = "hello world";

        var imageUrl = await imageService.UploadImageAsync(photo);
        ViewBag.Ult = imageUrl;
        //TempData["LatestImage"] = imageUrl;
        return View("Index");



    }

上面的代码是我的第一个Index actionresult结果,它可以单独运行,但是当我放另一个代码时,所有的事情都变得松散了:

    [HttpPost]
    public ActionResult Index(ModelVariables model)
    {  //code
}

摘要:我想这样做:

[HttpPost]
    public async Task<ActionResult> Index(HttpPostedFileBase photo + Modelvariables model)
    {  //code
}

我只想拥有一个httpPost方法,但要包含“照片”和“模型”

您不能有2个具有相同名称的[HttpPost]方法。 假设您有一个包含用于Modelvariables控件的Modelvariables以及一个文件输入,然后在POST方法中添加两个参数

public ActionResult Index(ModelVariables model, HttpPostedFileBase photo)

public HttpPostedFileBase Photo { get; set; }是,添加属性public HttpPostedFileBase Photo { get; set; } public HttpPostedFileBase Photo { get; set; } public HttpPostedFileBase Photo { get; set; }传递给ModelVariables类,以便您可以仅使用

public ActionResult Index(ModelVariables model)

暂无
暂无

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

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