How to send a model in jQuery $.ajax() post request to MVC controller method

前端 未结 7 1868
南方客
南方客 2020-11-27 02:47

In doing an auto-refresh using the following code, I assumed that when I do a post, the model will automatically sent to the controller:

$.ajax({
    url: \'         


        
7条回答
  •  失恋的感觉
    2020-11-27 03:02

    In ajax call mention-

    data:MakeModel(),
    

    use the below function to bind data to model

    function MakeModel() {
    
        var MyModel = {};
    
        MyModel.value = $('#input element id').val() or your value;
    
        return JSON.stringify(MyModel);
    }
    

    Attach [HttpPost] attribute to your controller action

    on POST this data will get available

提交回复
热议问题