【发布时间】:2015-09-18 12:36:26
【问题描述】:
我有一个允许用户创建Employee 的基本表单。一旦用户选择了submit 按钮,页面应该是redirected 到一个摘要页面。此摘要页面需要显示在 Employee 表单中添加的详细信息。
例如,我有一个如下所示的表单:
一旦用户选择Submit,它应该将用户重定向到以下页面:
我遇到的问题是获取 重定向 url。 我的 url 看起来像:http://www.localhost.com/Employee/1234/
1234代表Employeeid。我怎样才能拉那个Employee Id?
我当前的 HTML
<button type="submit" name="saveButton" id="saveBtn" class="btn btn-primary">Submit</button>
请注意,我使用的是 .NET,因此我愿意使用
Razor Syntax.
故事更新
在阅读了您所有的 cmets 之后,我深入挖掘了我的问题。这是我发现的。
有一个RouteConfig.cs 文件,路径如下:
routes.MapRoute(
name: "ListEmployee",
url: "Employee/{employeeId}",
defaults: new { controller = "Employee", action = "List"},
constraints: new {employeeId = "\\d+"}
)
因为我有这个路由,所以我决定修改这个控制器方法来利用它:
[HttpPost]
public ActionResult AddEmployee(ViewModel<EmployeeModel> model)
{
// logic here
return RedirectToAction("ListEmployee", new { employeeId = model.Body.Employee.Id, fromEmployeeProject = true });
}
问题:这完全崩溃了。声明:
No route in the route table matches the supplied values.关于我做错了什么有什么想法吗?
【问题讨论】:
-
表单提交后,我的代码需要找到分配给该用户的
EmployeeId。例如,提交后,我的URL将如下所示:http://www.localhost.com/Employee/1234 -
是否需要员工id才能在“摘要”页面显示新添加的
Employee对象? -
没错。我需要那个
Employee Id以便我可以查看特定Employee的摘要 -
如何保存员工记录?
EmployeeId属性是由服务器和/或数据库生成的吗?
标签: c# html asp.net-mvc