JQUERY ajax passing value from MVC View to Controller

后端 未结 6 1127
再見小時候
再見小時候 2020-11-27 16:41

What I want is to pass the value of txtComments from View (using jquery/ajax) to Controller.

The problem is the ajax/jquery doesn\'t accept script tags as string. M

6条回答
  •  生来不讨喜
    2020-11-27 17:17

    Here's an alternative way to do the same call. And your type should always be in CAPS, eg. type:"GET" / type:"POST".

    $.ajax({
          url:/ControllerName/ActionName,
          data: "id=" + Id + "¶m2=" + param2,
          type: "GET",
          success: function(data){
                // code here
          },
          error: function(passParams){
               // code here
          }
    });
    

    Another alternative will be to use the data-ajax on a link.

    Click Me!
    

    Assuming u had a div with the I'd _content, this will call the action and replace the content inside that div with the data returned from that action.

    Not really a direct answer to ur question but its some info u should be aware of ;).

提交回复
热议问题