Good day. In the ASP.MVC project, I encountered behavior that I was able to circumvent, but I cannot explain. The essence of the question: the form in the view sends to the controller an array of two string . The controller method must forward this array to another controller, where it has someone to handle. And I could not forward an array - instead of an array, only the type name comes to the parameters of the second controller.
The question is why is this happening? Is this normal behavior or have I done something wrong?
Code (first - working version): View (validators thrown out, but traces of them remained in the parameters):
@using (Html.BeginForm("Submit", "Home", FormMethod.Post, new { novalidate = "", name = "InputForm", ng_controller = "SubmitCtrl", role = "form" })) { <div class="form-group"> @Html.Label("Введите адрес сайта в поле ввода и нажмите кнопку") @Html.TextBox( "Url0", null, new { type = "url", @class = "form-control", required = "", placeholder = "Enter url here", id = "url11", ng_model = "url1" }) <div> @Html.Label("Выберите количество запросов к странице сайта") @Html.DropDownList("Url0", new SelectList(new string[] { "4", "5", "6", "7" }), new { @class = "form-control"}) </div> </div> <button type="submit" class="btn btn-primary" ng-click="Press()" ng-disabled="InputForm.$invalid">Отправить</button> <div ng-show="pressed"> <img src="~/Content/Image/please_wait.gif" /> </div> } A controller that receives data from the view and forwards it to another controller (extra blocks have been deleted).
[HttpPost] public ActionResult Submit(string [] Url0) { return RedirectToAction("Index", "Tool", new {url= Url0[0], attempts=Url0[1]}); } Controller processing data:
public ActionResult Index(string url, string attempts) { manager = new VMManager(); int att; if (Int32.TryParse(attempts, out att)) manager.AttemptsQuantiy = att; manager.VM = (SiteVM)manager.ParseUrl(url); if (manager.VM.PageResults.Count == 0) return RedirectToAction("Error", "Home", null); else return RedirectToAction("ShowResult", "Tool", null); } Non-working code:
public ActionResult Index(string[] url) in the Submit method:
return RedirectToAction("Index", "Tool", new {url= Url0}); or
return RedirectToAction("Index", "Tool", url= new string [] {Url0[0],Url0[1]});