单步执行我的代码后,我已经验证了 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"}
);