【发布时间】:2013-01-18 14:17:22
【问题描述】:
我遇到了表单收集问题。
我看到了一些表单,两个提交按钮都具有唯一的 name=""。在调试时,我在 formcollection 中的控制器上获取除提交按钮的“名称”之外的所有数据......我不知道为什么,因为我在其他表单中使用它并且效果很好。因此,我查看了代码,但是在不工作的formcol和工作的formcol上使用formcollection时找不到任何区别。我尝试重命名按钮,移动它们,添加我认为可以帮助的引用......没有。在每次提交时跳过我的条件,因为它只给我返回“false”,而我在 onclick 上的“上传”或“保存”按钮不包含...
所以我想请你帮忙。你能告诉我哪里可能出错了吗?谢谢大家!
这是在控制器中:
[HttpPost]
public ActionResult EditUser(EditUserVM model, int id, FormCollection c)
{
//c["upload"] is everytime set to null, 'cos c does't contain it
if (c["upload"] != null)
{
//.... some code
return RedirectToAction("Index", "Home");
}
if (ModelState.IsValid)
{
//.... next code
}
return View("EditUser", model);
}
这是在视图中:
@model PrukazOnline.ViewModels.EditUserVM
@{
ViewBag.Title = "EditUser";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"></script>
@using (Html.BeginForm("EditUser", "User", null, FormMethod.Post, new { @class = "form-horizontal", id = "formstep", enctype = "multipart/form-data" }))
{
@*Here is some code - @Html.TextBoxFor(x => x.something) and @Html.ValidationMessageFor(x => x.something) - all of these are in formcollection*@
.
.
.
.
<div>
<input type="submit" value="Nahrát" class="upl" name="upload" id="upload" />
</div>
<div class="submit_buttons">
<input type="submit" name="save" id="save" value="Uložit" />
</div>
}
【问题讨论】:
标签: asp.net-mvc-3 formcollection