通过我的代码后,我已验证collection.Get(“username”);在下面的代码中是null,这意味着我的post参数只是没有进入控制器。任何人都可以发现问题吗?为什么我的发布参数没有将其发送给我的控制器?
控制器:
public ActionResult Admin(uint id, FormCollection collection) {
var username = collection.Get("username");
var password = collection.Get("password");
Helper.CreateUser(username,password);
return View("AdministerUsers");
}
检视:
<% using (Html.BeginForm()){ %>
<fieldset>
<legend>Fields</legend>
<label for="username">username</label>
<%= Html.TextBox("username") %>
<label for="password">password:</label>
<%= Html.TextBox("password") %>
</fieldset>
<input type="submit" value="Add User" name="submitUser" />
<% } %>
路由:
routes.MapRoute(
"Admin",
"Admin/{id}",
new { controller = "Administration", action = "Admin"}
);
您已指定。删除此行并重试一次 –
@KundanSinghChouhan - 标签对表单值没有影响。 –
改为使用'Get(“username”)',而不是使用'collection [“username”]''。它不应该有所作为,但我很好奇,如果它。虽然我会建议使用Tejs解决方案,而不是FormCollection,因为它更安全。 –