我想知道是否可以使用Html.ActionLink()。
在conroller中: 我查询了我的数据库并将该数据传递给视图。
在视图中: 我已经使用该数据来填充输入,标签等...但是我想通过将相同的数据传递回控制器来减少查询命中数,因此可以在另一个视图上使用它。可以通过使用Html.ActionLink()将模型传递回控制器来完成吗?
控制器:
public ActionResult Account(int id, int? activelink, CombineModel CombineModel)
{
FetchLookupTables(CombineModel.Dwelling);
if (CombineModel == null)
{
return new FileNotFoundResult { Message = "No Account found for id " + id.ToString() };
}
else if (CombineModel.Dwelling == null)
{
CombineModel = new CombineModel()
{
Owner = OwnerDB.FindOne(GetUserId(), id),
Dwelling = DwellingDB.FindOne(GetUserId(), id),
Image = ImageDB.FindOne(GetUserId(), id)
};
return View(CombineModel);
}
else
{
return View(CombineModel);
}
}
查看:
@model Apartment.Models.CombineModel
@{
string[] names = {"Details", "Listings", "Profile"};
}
<ul>
@for(int i = 0; i < 3; i++)
{
<li>@Html.ActionLink(names[i],"Account", new { id = Model.Owner.ID, activelink = i, CombineModel = Model}, null)</li>
}
</ul>