我的控制器上有以下方法:
[HttpPost]
public ActionResult UnplannedCourses(int studentId)
{
var model = CreateUnplannedCourseModel(studentId);
return View("UnplannedCourses", model);
}
在我看来,我尝试:
<div class="unplannedcourses">
@Html.Action("UnplannedCourses", "Student", new { studentId = Model.StudentId })
</div>
但这会出现错误:在控制器“Digidos.MVCUI.Controllers.StudentController”上找不到公共操作方法“UnplannedCourses”。
如果我离开[HttpPost]
出来,然后它就可以工作了,但是我稍后再次从 javascript 使用该操作,所以我只想使用 POST 。
有什么想法吗?
我认为我最好的选择是基于 MVC 源的新属性:
public class ChildishAttribute : ActionMethodSelectorAttribute
{
private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Post);
public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
{
var isPost = _innerAttribute.IsValidForRequest(controllerContext, methodInfo);
var isChildAction = controllerContext.IsChildAction;
var isAjax = controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
return isChildAction || (isAjax && isPost);
}
}
[Childish]
public ActionResult UnplannedCourses(int studentId)
{
var model = CreateUnplannedCourseModel(studentId);
return View("UnplannedCourses", model);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)