如何使用html.beginform从服务器端获取结果

how to get the result from the server side using the html.beginform?

本文关键字:服务器端 获取 结果 beginform 何使用 html      更新时间:2023-09-26

我需要从服务器端获得结果。但是我用的是HTml。开始形成。我的示例代码如下

 @using (Html.BeginForm("actionname", "contollerr", FormMethod.Post, new { enctype = "multipart/form-data" }))
 {
 }
 public ActionResult actionname(IEnumerable<HttpPostedFileBase> files)
 {
  message = "your load in failed";
  return Json(new { success = false, message });   
 }

如何从控制器获得结果数据?

您没有使用ajax,所以这段代码不能工作,您需要这样的东西,验证摘要:我假设生成表单视图的操作和提交方法的操作具有相同的名称。

@using (Html.BeginForm("actionname", "contollerr", FormMethod.Post, new { enctype = "multipart/form-data" }))
 {
   @Html.ValidationSummary(true)
 }
 public ActionResult actionname(IEnumerable<HttpPostedFileBase> files)
 {
  message = "your load in failed";
  ModelState.AddModelError(string.Empty, message );
  return View();   
 }