Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does BeginForm("Foo") add a "Length" key to the query string?

I am not new to MVC so I am a bit baffled at why I can't change the URL of my POST when I click the submit button.

I have this simple view called PandoraRemovalTool.cshtml

@{
    ViewBag.Title = "PandoraRemovalTool";
}
@using (Html.BeginForm("PandoraGetDocsList"))
{
    <h2>Pandora Removal Tool</h2>    
    @Html.Label("Member number:")
    @Html.TextBox("txtMemberNumber")
    <br />
    <input type="submit" value="Search"/>
}

Because of it's simplicity I am not using a model, I only want to POST the txt value. However the URL is a bit odd. It's pointing to this path in the site:

<form action="/Administration/PandoraRemovalTool?Length=18" method="post" novalidate="novalidate">    
    <h2>Pandora Removal Tool</h2>
    <label for="Member_number:">Member number:</label>
    <input id="txtMemberNumber" name="txtMemberNumber" type="text" value=""/>        
    <br>
    <input type="submit" value="Search"/>
</form>

I don't understand where it's getting length=18 from. I want to post to this method:

[HttpPost]
public ActionResult PandoraGetDocsList(string txtMemberNumber)
{
    return RedirectToAction("PandoraRemovalTotal2", new {MemberNum = txtMemberNumber });
}

public ActionResult PandoraRemovalTotal2(string MemberNum)
{
    return View();
}

Some help please?

like image 837
nick gowdy Avatar asked Jul 11 '14 11:07

nick gowdy


1 Answers

Replace @using (Html.BeginForm("PandoraGetDocsList")) to @using (Html.BeginForm())

PandoraGetDocsList is the string of length 18 which you are getting in your post

If you want to redirect it to the action PandoraGetDocsList then do like this:

@using (Html.BeginForm("PandoraGetDocsList", "Administration", new { txtMemberNumber = someString }))

Explanation: Html.BeginForm does not accept a parameter as string.

like image 193
Arijit Mukherjee Avatar answered Nov 03 '22 01:11

Arijit Mukherjee