我有一个 ajax actionlink,我将模型和actionattribute作为附加的 html 属性传递
@Ajax.ActionLink("Add action", "SomeAction", "SomeController", Model, new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "SomePartial", HttpMethod = "POST" }, new { actionattribute = "a", @class = "new" })
actionattribute属性以正确的值呈现在 html 源代码中。
模型很好地传递给动作,但 html actionattribute参数为空,而不是显示值a。
任何想法为什么?我错过了什么?如何让参数工作?
编辑 ***
模型也不传递值。很抱歉造成混乱。最初在 Index 操作中设置的模型值将传递给 SomeAction。否则,SomeAction 不会看到对表单中这些值的任何更新。
这是控制器
[HttpPost]
public ActionResult SomeAction(SomeModel model, string actionattribute)
{
ViewBag.Msg = "actionattribute: " + actionattribute;
ViewBag.Msg += "<br />Counter: " + model.Counter;
ViewBag.Msg += "<br />Code: " + model.Code;
ViewBag.Msg += "<br />Type: " + model.Type;
return this.PartialView("_SomePartialView", model);
}
编辑 2 ***
我不能使用 Ajax.BeginForm 而不是 Ajax.ActionLink,因为我已经有页面的 Html.BeginForm 并且不能在其中嵌套 ajax 表单。
_SomePartialView 是局部视图,它使用的模型是“主”模型的属性,并通过 _SomePartialView 传递给该局部视图
@Html.Partial("~/Views/Main/_SomePartialView.cshtml", Model.SomeProperty)