mvc从视图(输入类型)传递信息到控制器

时间:2021-11-21 21:33:10

I am new on mvc and i have this code on my view

我是mvc的新手,我在我看来有这个代码

 $('#btnSearch').click(function(){

    var idnumber = $('#txtIDNumber').val();
        var startdate = $('#txtStartDate').val();
        var enddate = $('#txtEndDate').val();

        $.ajax({
            url: '/MyController/GetUserInput',
            data: {'id' : idnumber,'start date':startdate,'end date':enddate},
            type:"post",
            cache:false,
            success: function(){
            },
            error:function(){
                alert("error");
            }

        });
    });

I would like to pass this info from my input to my contoller. How do i go about doing this, ive been googling but the answers i find are not helping. Whats wrong with my code? This is my controller

我想将此信息从我的输入传递给我的控制器。我如何去做这件事,我一直在谷歌搜索,但我找到的答案没有帮助。我的代码有什么问题?这是我的控制器

 public ActionResult GetUserInput(Mymodel model )
    {

        var idnumber = model.ID_Number;
        var startdate = model.Start_Date;
        var enddate = model.End_Date;



        return View("Index");
    }

please help

1 个解决方案

#1


0  

So i figured out a solution, the problem was with my ajax. this is how its supposed to be:

所以我想出了一个解决方案,问题出在我的ajax上。这是它应该如何:

$('#btnSearch').click(function () {

        var idnumber = $('#txtIDNumber').val();
        var startdate = $('#txtStartDate').val();
        var enddate = $('#txtEndDate').val();

        $.ajax({
            url: '/Mycontroller/GetUserInput',
            data: { ID_Number: idnumber, Start_Date: startdate, End_Date: enddate },
            type: "post",
            cache: false,
            success: function () {
            },
            error: function () {
                alert("error");
            }

        });
    });

and the code on mycontoller stays the same. Im hoping this will help someone else. Thank you!

并且mycontoller上的代码保持不变。我希望这会帮助别人。谢谢!

#1


0  

So i figured out a solution, the problem was with my ajax. this is how its supposed to be:

所以我想出了一个解决方案,问题出在我的ajax上。这是它应该如何:

$('#btnSearch').click(function () {

        var idnumber = $('#txtIDNumber').val();
        var startdate = $('#txtStartDate').val();
        var enddate = $('#txtEndDate').val();

        $.ajax({
            url: '/Mycontroller/GetUserInput',
            data: { ID_Number: idnumber, Start_Date: startdate, End_Date: enddate },
            type: "post",
            cache: false,
            success: function () {
            },
            error: function () {
                alert("error");
            }

        });
    });

and the code on mycontoller stays the same. Im hoping this will help someone else. Thank you!

并且mycontoller上的代码保持不变。我希望这会帮助别人。谢谢!