我在 asp.net mvc 中做一个项目。我想在视图中显示特定人的详细信息。我必须加入 2 个表才能显示数据。为此我做了:
控制器:
[HttpGet]
public ViewResult DisplayData()
{
ViewBag.Designation1up = new SelectList(db.Designations, "Designation1up", "DesignationInternal", "DesignationExternal");
return View();
}
[HttpPost]
public ActionResult DisplayData(Employee emp)
{
try
{
object s = Session["EmployeeID"];
var sessval = s.ToString();
var data1 = (from e in db.Employees.Where(c => c.EmployeeID == sessval) join d in db.Designations on e.Designation1up equals d.Designation1up select e).SingleOrDefault();
return View(data1);
}
catch (Exception e)
{
}
ViewBag.Designation1up = new SelectList(db.Designations, "Designation1up", "DesignationInternal",emp.Designation1up);
return View(emp);
}
风景:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<ResourceTracking.ViewModel.AdminDetailsModel>" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>DisplayData</title>
</head>
<body>
<fieldset>
<legend>AdminDetailsModel</legend>
<div class="display-label">EmployeeID</div>
<div class="display-field"> <%: Html.DisplayFor(model => model.EmployeeID) %> </div>
<!--...(same DIV 4 other fields)-->
</fieldset>
</body>
</html>
我的问题是,当我调试代码时,编译器没有进入该HttpPost
方法。它只是调试HttpGet
方法并给出输出,但除非HttpPost
运行,否则输出将不正确。我该怎么办?