0

It seems that once I define my Form like -->
using (Html.BeginForm("Create", "MyController", FormMethod.Post, new { id = "myForm" }))

The additional parameters being passed are now null.

MyController/Create/4?pid=61&status=Initiated

pid and status returns null although the parameters are being passed as above. What is causing these querystring parameters to be be null?

Using Request["myparameter"] or simply getting value from action method parameter returns null.

1
  • Can you show your View and Controller code and then we can see what you're doing wrong. Commented Jun 27, 2011 at 15:41

2 Answers 2

1

Try this

Html.BeginForm("Create", "MyController", new { pid = Request.QueryString["pid"] },   FormMethod.Post, new { id = "myForm" }))
Sign up to request clarification or add additional context in comments.

Comments

0

What you are saying is very weird as the following works perfectly fine for me:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(string pid, string foo)
    {
        // the pid and foo parameters are correctly assigned here
        return View();
    }
}

and in the view:

@using (Html.BeginForm("Index", "Home", new { pid = "63" }, FormMethod.Post, new { id = "myForm" }))
{
    @Html.TextBox("foo", "some value")
    <input type="submit" value="OK" />
}

5 Comments

HERE IS MY Action Method-------> public ActionResult Create(WizardViewModel wizardViewModel, int id, int? pid, string SavedJsonRoles, string SavedJsonMetrics, string Status, bool NOVALIDATION) {
My hidden values e.g. SavedJsonMetircs are returned with no problem.
@Nate, yes this should also work with view models as action arguments. Just make sure that you are passing the other values (pid, status) as query string parameters in the request. See my example of how to use Html.BeginForm to achieve this (I have hardcoded the pid value but you could fetch it from the current Request as well if it is present: new { pid = Request["pid"] }).
The strange thing is that the parameters get passed in if I change my using statement to --> using (Html.BeginForm()) {}
@Nate, yes, that's because when you use the Html.BeginForm() helper without specifying any argument it simply uses the current url as action. So if there were argument in it they are automatically copied. If you use some of the other overloads you need to specify them manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.