单屏幕中的多个操作 [英] Multiple action in Single Screen
问题描述
我需要在单个屏幕中执行创建,列表,更新,并在Mvc中显示separete视图。
任何人都可以建议如何执行此操作。我尝试了部分视图但无法完成任务。
请帮助
这是我的观点
I need to perform Create, List, Update in Single screen insted of separete views in Mvc.
Can anybody suggest how to do this. I tried with partial view but could not accomplish the task.
Pls help
this is my view
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcMaster.Models.Mast_Lab>>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Index</title>
</head>
<body>
<table>
<tr>
<%Html.RenderPartial("Create"); %>
</tr>
<tr>
<th></th>
<th>
iMast_Lab_id
</th>
<th>
cLab_Name
</th>
<th>
dCreate_dt
</th>
<th>
bActive
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.iMast_Lab_id }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.iMast_Lab_id })%> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.iMast_Lab_id })%>
</td>
<td>
<%: item.iMast_Lab_id %>
</td>
<td>
<%: item.cLab_Name %>
</td>
<td>
<%: String.Format("{0:g}", item.dCreate_dt) %>
</td>
<td>
<%: item.bActive %>
</td>
</tr>
<% } %>
</table>
</body>
</html>
这是控制器类
private LabDataContext db = new LabDataContex t();
公共ActionResult索引()
{
var lb =(来自db.Mast_Labs中的l选择l); // .FirstOrDefault();
返回View(lb);
//Models.Mast_Lab DocMstrEdit =(来自db.Mast_Labs中的v < br $>
//选择v).FirstOrDefault();
//返回View(DocMstrEdit);
}
公共ActionResult创建()
{
返回查看();
}
public ActionResult CreateNew(string LabName)
{
var lb = new Mast_Lab();
lb.cLab_Name = LabName;
lb.dCreate_dt = DateTime.Now;
lb.bActive = 1;
db.Mast_Labs.InsertOnSubmit(lb);
db.SubmitChanges();
返回View() ;
}
and this is controller class
private LabDataContext db = new LabDataContext();
public ActionResult Index()
{
var lb = (from l in db.Mast_Labs select l);//.FirstOrDefault();
return View(lb);
//Models.Mast_Lab DocMstrEdit = (from v in db.Mast_Labs
// select v).FirstOrDefault();
//return View(DocMstrEdit);
}
public ActionResult Create()
{
return View();
}
public ActionResult CreateNew(string LabName)
{
var lb = new Mast_Lab();
lb.cLab_Name=LabName;
lb.dCreate_dt=DateTime.Now;
lb.bActive=1;
db.Mast_Labs.InsertOnSubmit(lb);
db.SubmitChanges();
return View();
}
推荐答案
查看以下链接,它解释了您所需的确切内容:
传递到字典中的模型项的类型为'',但此字典需要类型为'System.Collections.Generic.IEnumerable 的模型项[ ^ ]
祝你好运。
Check out following link it explains exact what you need :
The model item passed into the dictionary is of type '', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable[^]
Good luck.
这篇关于单屏幕中的多个操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!