【问题标题】:how to get the result from the server side using the html.beginform?如何使用 html.beginform 从服务器端获取结果?
【发布时间】:2013-04-11 11:28:59
【问题描述】:

我需要从服务器端获取结果。但我使用的是 HTml.Begin 表单。我的示例代码如下

 @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上传文件吗?
  • 不,我只是通过 html.beginform 上传文件

标签: javascript asp.net-mvc asp.net-mvc-3 html.beginform


【解决方案1】:

你没有使用 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();   
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 2021-05-06
    • 2017-02-17
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多