Ajax没有将数据发布到操作中 [英] Ajax not posting data to action
本文介绍了Ajax没有将数据发布到操作中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试发布视图中的值,但它不会执行action.only null正在显示行动
I am trying to post the value from view but its not going to action.only null is showing in action
<script>
$(document).ready(function () {
$("#btn_submit").click(function () {
var c = $("#s_country").val();
var s = $("#s_stat").val();
var ct = $("#s_city").val();
var param = {
country: c,
state: s,
city:ct
};
debugger
$.ajax({
url: "/Home/Existing_data/", // action name
data: JSON.stringify(param),
type: "POST",
dataType: 'json',
cache: false,
contentType: "application/jsonrequest; charset=utf-8",
success: function (data) {
}
});
});
});
</script>
//这是我的控制器代码
// this is my controller code
public ActionResult Existing_data( tempdata obj) // after debugging only null value showing here
{
tbl_country cnt = new tbl_country();
tbl_state st=new tbl_state();
if(cnt.cid ==obj.c_id && st.sid==obj.s_id)
{
tbl_city tbct = new tbl_city();
tbct.ctname = obj.ctnam;
db.tbl_city.Add(tbct);
db.SaveChanges();
}
return RedirectToAction("Country_data");
}
//这是类
// this is class
public class tempdata
{
public int c_id { get; set; }
public int s_id { get; set; }
public int ct_id { get; set; }
public string cnam { get; set; }
public string snam { get; set; }
public string ctnam { get; set; }
}
我的尝试:
我在互联网上阅读了一些内容,但我无法解决。请帮助
What I have tried:
I read some stuff on internet but i am not able to solve.please help
推荐答案
(文件).ready( function(){
(document).ready(function () {
(#btn_submit)。click(function(){
var c =
("#btn_submit").click(function () { var c =
(#s_country ).val();
var s =
("#s_country").val(); var s =
这篇关于Ajax没有将数据发布到操作中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文