mvc提交表单的问题(应该不难)
我有个通过查询条件,查列表的页面。例如通过查公司名称,岗位,显示出员工姓名的列表。
问题是
列表本身是一个model,公司名称和岗位又是一个model。可cshtml只能加一个model.
[HttpPost]
public ViewResult Index(FormCollection formValues)
获取不到formValues
望给个通过查询条件得到查询列表的例子,或者能帮我答疑解惑,谢谢
代码如下:
cshtml:
@model IEnumerable<Expert.Models.L_ExpertAll>;
@using (Html.BeginForm()) {
<fieldset>
抽取人数<input id="txtTop" type="text" />,专业<select id="ddlMajor"></select>,回避单位<input id="txtCompany" type="text" />,抽取范围<select id="ddlLv"></select><input
id="Submit1" type="submit" value="submit" />
</fieldset>
}</td>
<tr>
<th>
姓名
</th>
<th>
专业
</th>
<th>
公司名称
</th>
<th>
所属省市
</th>
<th>
职称
</th>
<th>
单位电话
</th>
<th>
家庭电话
</th>
<th>
手机
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Major)
</td>
<td>
@Html.DisplayFor(modelItem => item.Company)
</td>
<td>
@Html.DisplayFor(modelItem => item.Lv)
</td>
<td>
@Html.DisplayFor(modelItem => item.DB_XML.JobTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.DB_XML.WorkTel)
</td>
<td>
@Html.DisplayFor(modelItem => item.DB_XML.FamilyTel)
</td>
<td>
@Html.DisplayFor(modelItem => item.DB_XML.MTel)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
再说cs代码:
public ViewResult Index()
{//listall代码已实现
return View(listall);
}
[HttpPost]
public ViewResult Index(FormCollection formValues)
{
//listall代码已实现
return View(listall);
} mvc提交表单
[解决办法]
再 定义一个 model,包含两个model
class AccountViewData
{
//public 公司model
public string AccountName{get;se;}
public 员工model
}
[解决办法]
不要认为modal就是数据表结构,自己随便定义个结构,都可以当做数据结构传递,定义一个包含查询内容的modal,传过来,自己组织好数据传回去
[解决办法]
多表查询返回多个model 最简单的是 把表里的ID换成 实体对象好操作 或者是 新建一个MODEL把 需求的数据都写好 封装成字段
[解决办法]
你可以自己新建一个model,里面是你需要的字段,比如公司名称、岗位、员工姓名、员工公司关系id等,把这个model传给视图就行了。
[解决办法]