0

我有一个在同一页面上多次存在的部分视图。这被添加到视图中:

@Html.Partial("PersonalTagPartial", Model.PT, new ViewDataDictionary{{"TagTypeControl", 1}} )

@Html.Partial("PersonalTagPartial", Model.PT, new ViewDataDictionary{{"TagTypeControl", 0}} )

然后在部分视图中,我得到了这样的提交表单:

@using (Html.BeginForm("AddPersonalTag", "Post", FormMethod.Post, new { id = "frmAddPersonalTags" })){

当 TagTypeControl 设置为 0 时,如何将 AddPersonalTag 更改为 RemovePersonalTag?

4

1 回答 1

0

试试这样:

@using (Html.BeginForm((ViewBag.TagTypeControl == "1" ? "AddPersonalTag" : "RemovePersonalTag"), "Post", FormMethod.Post, new { id = "frmAddPersonalTags" }))
{
    ...
}

但您也可以直接将动作名称传递给部分:

@Html.Partial("PersonalTagPartial", Model.PT, new ViewDataDictionary { { "SubmitTo", "AddPersonalTag" } })
@Html.Partial("PersonalTagPartial", Model.PT, new ViewDataDictionary { { "SubmitTo", "RemovePersonalTag" } })

然后在部分内部:

@using (Html.BeginForm(ViewBag.SubmitTo, "Post", FormMethod.Post, new { id = "frmAddPersonalTags" }))
{
    ...
}
于 2013-03-17T14:19:53.423 回答