【问题标题】:RedirectToAction is not working in ActionResultRedirectToAction 在 ActionResult 中不起作用
【发布时间】:2020-09-25 20:44:08
【问题描述】:
public ActionResult UploadImage(HttpPostedFileBase file)
{           
     if (file != null && file.ContentLength > 0)
     {
          try
          {
              string path = Path.Combine(Server.MapPath("~/Images"),
                    Path.GetFileName(file.FileName));
              file.SaveAs(path);
              ViewBag.FileStatus = "File uploaded successfully";
          }
          catch (Exception ex)
          {
              ViewBag.FileStatus = "ERROR:" + ex.Message.ToString();
          }
     }
     else
     {
            ViewBag.FileStatus = "You have not specified a file.";
     }
 
     return Json("No files selected.", JsonRequestBehavior.AllowGet);
}

第二个ActionResultPhysicianBiodata()

public ActionResult PhysicianBiodata (int? Id)
{
    PhysicianBiodata newForm = new PhysicianBiodata();
    if (Id <= 0 || Id == null)
    {
        return RedirectToAction("UploadImage", "ServiceCompendium", 
                {HttpPostedFileBase httpPostedFileBase});
    }
    else
    {
        newForm = compendiumData.GetPhysicianBiodatas().Where(x => x.ID == Id)
                 .FirstOrDefault();
    }
    return View(newForm);
}

我想将此UploadImage() 称为PhysicianBiodata(),但它不起作用。你能帮帮我吗....

【问题讨论】:

  • 告诉我们什么是不工作的。参数?
  • 在参数周围给出 5 个错误,例如;{}等。
  • 确保你有正确的打开和关闭{ };

标签: c# json model-view-controller


【解决方案1】:

你能修正重定向的最后一个参数吗?

类似

return RedirectToAction("UploadImage", "ServiceCompendium", { new @file =httpPostedFileBase});

另外,PhysicianBiodata 方法中的 httpPostedFileBase 在哪里?

【讨论】:

  • 是否可以将 POST 请求重定向到另一个 POST 操作?
  • return RedirectToAction("UploadImage", "ServiceCompendium", {new @file= HttpPostedFileBase});不管用。我需要上传照片,这就是我调用这个函数的原因。不知道我在哪里做错了..请帮忙。
  • 在这个 httppostedfilebase 周围得到相同的括号,分号错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-06
  • 1970-01-01
  • 2014-04-19
相关资源
最近更新 更多