我有註冊表單和用於查看所有記錄的表格(表格).. 但我不知道如何從不同的操作方法顯示 我的代碼顯示下面如何調用其他操作方法並在我的視圖中創建列表
@using (Html.BeginForm("Create", "Bathrooms", FormMethod.Post))
{
@Html.LabelFor(model => model.BathRoomDetails)
@Html.TextBoxFor(model => model.BathRoomDetails)
<br/>
@Html.LabelFor(model => model.shortstring)
@Html.TextBoxFor(model => model.shortstring)
<br/>
<button type="submit" class="btn btn-primary"/> Create</button>
<button type="submit"> View All</button>
}
和我的格子碼
<table>
@foreach (var a in ViewBag.data as List<RealEstate.Models.BathRoomVM>)
{
<tr>
<td>@a.BathRoomDetails</td>
<td>@a.BActive</td>
</tr>
}
</table>
和我的控制器
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(BathRoomVM Bathrooms)
{
ModelState.Clear();
var realContext = new RealEstateDBContext();
Bathroom Bathroomobj = new Bathroom();
Bathroomobj.BathRoomDetails = Bathrooms.BathRoomDetails;
Bathroomobj.shortstring = Bathrooms.shortstring;
realContext.Bathrooms.Add(Bathroomobj);
realContext.SaveChanges();
ModelState.Clear();
return View();
}
public ActionResult Get()
{
var realContext = new RealEstateDBContext();
var rslt = (from bathroom in realContext.Bathrooms
select new BathRoomVM { BathRoomDetails = bathroom.BathRoomDetails, BActive = bathroom.BActive, Bcancelled = bathroom.Bcancelled }).Where(m => m.BActive == true && m.Bcancelled == false).ToList();
ViewBag.data = rslt;
return View();
}
我需要加載或顯示網格後,單擊ViewAll按鈕..我已經嘗試了不同的方式,但他們都沒有工作..請幫助我如何實現,我從最近2天卡住了這個問題.. 我有使用
public ActionResult Create()
{
var realContext = new RealEstateDBContext();
var rslt = (from bathroom in realContext.Bathrooms
select new BathRoomVM { BathRoomDetails = bathroom.BathRoomDetails, BActive = bathroom.BActive, Bcancelled = bathroom.Bcancelled }).Where(m => m.BActive == true && m.Bcancelled == false).ToList();
ViewBag.data = rslt;
return View();
}
我以這種方式得到的結果,(需要更多的時間從數據庫中檢索數據)過慢..
[我需要調用其他的操作方法,並在我看來,創建一個列表]
感謝朋友我明白了... – 2014-09-05 16:29:36