如何在mvc中在服务器中发布值 [英] how to post value in server in mvc

查看:80
本文介绍了如何在mvc中在服务器中发布值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在MVC c#中的POST方法上发布值。在post值之后,它返回MVC上来自服务器的值。我需要解决方案。请发送一些样品或链接。



这里是使用knockoutjs的服务器中的邮政编码代码。



代码:



Hi,

how to post value on POST method in MVC c#. after post value it returns with value from server on MVC. i need solution for this asap. pls send some samples or link.

here below code for post value in server using knockoutjs.

code:

var items = ko.toJSON(self.empnamee);
     alert(items);
     $.ajax({
         type: "POST",
         url: "http://192.170.1.01/API1/api/home"+self.empnamee,

         data: items,
         processData: false,
         success: function (data) {
             alert('success');
         },
         statusCode: {
             404: function () {
                 alert('Failed');
             }
         }
     });

推荐答案

.ajax({
type: POST
url: http://192.170.1.01/API1/api/home + self.empnamee,

data:items,
processData: false
成功:函数(数据){
alert(' 成功');
},
statusCode:{
404 :function(){
alert (' 失败');
}
}
}) ;
.ajax({ type: "POST", url: "http://192.170.1.01/API1/api/home"+self.empnamee, data: items, processData: false, success: function (data) { alert('success'); }, statusCode: { 404: function () { alert('Failed'); } } });


Hello Mohan,

Hello Mohan,
First up all concentrate on principle for calling action and controller in MVC.  Currently as per your code you are calling url "http://192.170.1.01/API1/api/home"+self.empnamee" ,  Now here for time being I assume that "api" is your controller and "home" is your action. But here in your code looks like that your action name is changing with respect to employee name. This would now going to work for you.
    By taking again your url as an example,  http://192.170.1.01/API1/api/home. Now here api will be controller, home become action, and self.empnamee should be parameter for your action. One more important thing you have been used API1 in url so that you should be make an entry to RouteConfig.cs as routes.MapRoute("AjaxCall", " API1/{controller}/{action}/");
I hope this will help you


这篇关于如何在mvc中在服务器中发布值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆