Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use the RedirectToAction correct
    text
    copied!<p>I have an problem using the RedirectToAction method in mvc. My Map route look like this.</p> <pre><code> routes.MapRoute( "Project", // Route name "{Controller}/{Action}/{projectId}/{machineName}/{companyId}", new { controller = "Project", action = "Directives", projectId = 0, machineName = "", companyId = 0 } // Parameter defaults); </code></pre> <p>And the return look like this:</p> <pre><code> return RedirectToAction("Directives", "Project", new { projectId = projectId, machineName = project.MachineName, CompanyId = user.Company_Id }); </code></pre> <p>It works prefect, but the i use the RedirectToAction it still looks like this</p> <pre><code>http://localhost:1843/Project/Directives?projectId=48&amp;machineName=Netduino&amp;companyId=27 </code></pre> <p>Controller:</p> <pre><code> [HttpPost] [ValidateInput(false)] public ActionResult Create(Project project, string text) { ViewBag.MachineType = new List&lt;string&gt;(new string[] { "Machine Type A", "Machine Type B", "Machine Type C", "Machine Type D", "Machine Type E" }); if (ModelState.IsValid) { UserAccess user = (UserAccess)(Session["UserAccessInfo"]); Int64 projectId = DataBase.DBProject.InsertProject(project.ProjectNumber, project.MachineName, project.MachineNameEnglish, 1, project.Serial, text, user.Company_Id,project.MachineType); return RedirectToAction ("Directives", "Project", new { projectId = 48, machineName = "Netduino", companyId = 27 }); // return RedirectToAction("Directives", "Project", new { projectId = projectId, machineName = project.MachineName, CompanyId = user.Company_Id }); } else { ModelState.AddModelError("", "Invalid username or password"); } return View(); } </code></pre> <p>The receiving controller:</p> <pre><code>public ActionResult Directives(int projectId, string machineName, int companyId) { convertedDirectives = new List&lt;Models.Directives&gt;(); ViewBag.MachineName = machineName; ViewBag.ProjectId = projectId; List&lt;object&gt; Directives = new List&lt;object&gt;(); if (ModelState.IsValid) { Directives = DataBase.DBProject.GetDirectives(companyId); foreach (List&lt;object&gt; dir in Directives) { Directives newDirective = new Models.Directives(); newDirective.CompanyID = Convert.ToInt32(dir[0]); newDirective.DirectiveId = Convert.ToInt32(dir[1]); newDirective.Id = Convert.ToInt32(dir[2]); newDirective.DirectiveName = Convert.ToString(dir[3]); newDirective.DirectiveNameShort = Convert.ToString(dir[4]); newDirective.Created = Convert.ToDateTime(dir[5]); convertedDirectives.Add(newDirective); } } else { ModelState.AddModelError("", "An error has "); } ViewBag.DirectivesList = convertedDirectives; return View(); } </code></pre> <p>But the way i want it is like this.</p> <pre><code>http://localhost:1843/Project/Directives/48/Netduino/27 </code></pre> <p>But the weird thing is that i can manual type in the Url an it works prefect. What is im doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload