如何在mvc4应用程序中使用jquery和ajax进行CRUD操作 [英] How to use jquery with ajax to CRUD operations in mvc4 application
问题描述
我想通过使用json将我的所有值传递给控制器操作方法。
你能否提供带有ajax相关链接的JSON和JQuery用于mvc4应用程序开发
特别是对于CRUD操作。
你好DG Kumar,
下面是一个关于控制器动作的ajax调用的一个小例子,用于将数据保存到数据库中。
Ex: -
< pre lang =c#> function UpdateUserName(ID,Name){
var objParams = {id:ID,name:Name};
.ajax({
type: POST,
url:{application context path} + Common / UpdateUserName,
data :objParams,
contentType: 应用/ JSON; charset = utf-8,
dataType: json,
async : true ,
成功:函数(响应){
if (response!= null && response!= undefined){
// 显示成功消息
}
},
错误:function( XMLHttpRequest,textStatus,errorThrown){
// 在此处理错误
}
});
}
希望这对你有所帮助。
这里还有一些链接为你提供了一些正确的方法来使用MVC和a做所有的CRUD操作熔点; JQuery。
1) http://www.dotnet-tricks.com/Tutorial/mvc/42R0171112-CRUD-Operations-using -jQuery-dialog,-Entity-Framework-and-ASP.NET-MVC.html [ ^ ]
2) http:// www.c-sharpcorner.com/Blogs/14611/insert-delete-update-read-crud-operation-in-mvc-4-0-using.aspx [ ^ ]
您好,
参考: CRUD操作 - 第1部分
和
使用ASP.NET MVC4中的部分视图和jQueryUI进行CRUD操作 - 第2部分
谢谢
I want to pass my all values to controller action method by using json.
Could you please provide the JSON and JQuery with ajax related links which are use to mvc4 application development
especially for CRUD operations.
Hi DG Kumar,
Here is a small example of an ajax call to a controller action to save data into database.
Ex :-
function UpdateUserName(ID, Name) { var objParams = { id: ID, name:Name };
.ajax({ type: "POST", url: { application context path } + "Common/UpdateUserName", data: objParams, contentType: "application/json; charset=utf-8", dataType: "json", async: true, success: function (response) { if (response != null && response != undefined) { // Show success message } }, error: function (XMLHttpRequest, textStatus, errorThrown) { // Handle errors here } }); }
Hope this can be of help for you.
Also here some of the links to give you some correct way to do all CRUD operation using MVC & JQuery.
1) http://www.dotnet-tricks.com/Tutorial/mvc/42R0171112-CRUD-Operations-using-jQuery-dialog,-Entity-Framework-and-ASP.NET-MVC.html[^]
2) http://www.c-sharpcorner.com/Blogs/14611/insert-delete-update-read-crud-operation-in-mvc-4-0-using.aspx[^]
Hello,
Refer : CRUD Operations using Partial View and jQueryUI in ASP.NET MVC4 - Part 1
and
CRUD Operations using Partial View and jQueryUI in ASP.NET MVC4 - Part 2
thanks
这篇关于如何在mvc4应用程序中使用jquery和ajax进行CRUD操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!