0
在视图中,如何在控制器或项目中的其他类中调用方法?我可以这样做吗?从视图中可以调用控制器中的方法吗?
在视图中,如何在控制器或项目中的其他类中调用方法?我可以这样做吗?从视图中可以调用控制器中的方法吗?
,如果你需要打电话给你的视图中的操作方法需要使用ChildActionOnly
:
[ChildActionOnly]
public ActionResult action1()
{
//
return PartialView();
}
在你看来
则:
@Html.Partial("action1")
,但如果你想打电话给像辅助类的方法,简单地你可以这样:
@helper ShowTree()
{
//some code
}
试试这个,
下面介绍如何查看呼叫控制器操作事件的所有格式。
- >使用Ajax调用beginform
@using (Ajax.BeginForm("ContainerSizeDetail", "Content", FormMethod.Post, null, new { @class = "" }))
{}
[HttpPost]
public ActionResult ContainerSizeDetail(ContainerSizeModel model)
{}
- >通话与Beginform
@using (Html.BeginForm("VendorContactDetail", "VendorAccount", FormMethod.Post, new { id = "frmVendorContact" }))
{}
[AllowAnonymous]
public ActionResult VendorContactDetail()
{}
- >使用Ajax调用呼叫
var request = $.ajax({
url: "http://localhost/ProjectDirectory/VendorAccount/ValidateUser",
type: 'POST',
cache: false,
data: JSON.stringify(returnValue),
dataType: 'json',
contentType: 'application/json; charset=utf-8'
});
[AllowAnonymous]
[HttpPost]
public ActionResult ValidateUser(VendorRegistrationModel model)
{}