客户端到服务器端数据传递C#MVC

时间:2019-02-02 09:18:43

标签: jquery asp.net-mvc model-view-controller

在MVC中是否有其他方法可以传递和调用控制器方法。

通常我知道

@Html.Beginform('MethodName','Controller Name')

<form action="/{Controller Name}/{Method Name}" method="post">  
    <div>My Html Form</div>       
</form> 

$.ajax({
    type: "POST",
    data: {},
    url: "../{Controller Name}/{Method Name}",
    successs: function(response) {},
    error: function(response) {}
});

是否有任何其他方法是吗?如果让我解释一下它的用法和说明。

2 个答案:

答案 0 :(得分:1)

是的!正如您所期望的那样,还有一个:

@using (Ajax.BeginForm("MethodName", "ControllerName", new AjaxOptions {
    InsertionMode = InsertionMode.Replace, 
    UpdateTargetId = "targetReplaceId", //target div that will be replaced with the response
    LoadingElementId = "loader" // div with .gif loader - that is shown when data are loading   
}))
{
    // Here is your form input fields

    <input  type="submit" value="Submit" />
}

答案 1 :(得分:0)

这取决于您尝试使用已提供的特定代码时遇到的问题 您能告诉我们具体的问题吗 该解决方案可能比寻找替代方法容易

相关问题