c# - How pass Array to action with Ajax.ActionLink from view? -
I am using razor for a controller and passing the array. The array contains the type of string. Example array in the view:
@ {. . . String [] Mainstatus = Vybug.mnus; }. . @ Ajax Exynalink ("Lincoln", Action-name, ControllerName, New {status = menustatus}, New Ajax option {HttpMethod = "Post"}, blank) My controller is:
Public action ActoinName (parameter string [] position) {} The status variable contains the value of "system.string []". I hope the array values are sent to the action.
You can not arrange them in the ActionLink like this. Because by default mvc.net calls toString method and it returns system.string [] . But you can use two alternative methods. Before joining, first join the array of stars, and then divide them into the array (in the controller) like: ... new {status = String.Join (";", Mainstatus)) ... In view and in this controller:
Public action ActoinName (string allstats) {var status = allStatus.Split (new [] {";"}}); Or you can use AJAX posts with jquery:
& lt; A href = "javascript: ajaxCall ()" id = "ajax call" & gt; linkAjax & lt; / A & gt; & Lt; Script & gt; Function AJAX call ($ {AGGX ({Traditional: true, type: "post", url: "@ Url.Action. (" ActionName ")", data: {status: [@forch (word st in mainstats) {@ : '@ Cents'}}}, success: function (data) {/ doing something}}}}};
Comments
Post a Comment