我有一个显示帐户资产的视图。
@{
string returnUrl = returnUrl = Url.Action("Details", "AccountEntries", new { page = Model.Pages.Page }, null);
}
...
@foreach (ViewDetails.ViewAsset item in Model.ViewAssets)
{
<tr>
<td>
@item.Asset.Description
</td>
<td>
@item.Asset.Amount.ToGBString()
</td>
<td>
@Html.ActionLink("Edit", "Edit", "Assets", new { id = item.Asset.Id, returnUrl = returnUrl }, null)
</td>
</tr>
}
我想使用部分视图和 ajax 动态插入(创建)行。
@{
string returnUrl = returnUrl = Url.Action("Details", "AccountEntries", new { page = Model.Pages.Page }, null);
}
...
@foreach (ViewDetails.ViewAsset item in Model.ViewAssets)
{
@Html.Partial("_Asset", item)
}
使用部分视图:
@model ViewDetails.ViewAsset
<tr>
<td>
@Model.Asset.Description
</td>
<td>
@Model.Asset.Amount.ToGBString()
</td>
<td>
@Html.ActionLink("Edit", "Edit", "Assets", new { id = Model.Asset.Id, returnUrl = returnUrl }, null)
</td>
</tr>
和 AJAX :
public ActionResult MyAjaxAction(MyViewModel model)
{
return PartialView("_Asset", model);
}
问题:我的returnUrl
是在主视图中生成的,我不知道如何在视图和ajax调用的局部视图中使用它。
对于视图,我可以使用ViewDataDictionary
传递它,但是我如何对 Ajax 调用执行相同操作?我是否在 Ajax 调用中发送了Url,或者有更好的方法吗?
答案 0 :(得分:0)
您可以将returnUrl放在ViewBag中并在部分视图中访问它。