I'm sending some param via form post from my template and the action in my controller is handling it accordingly.

Now I want to write a test case for that action. How should I make that dummy request so that Request.Form["selectedSuppliersHidden"] will work in controller action?

有帮助吗?

解决方案

You shouldn't really need to use Request.Form in MVC

Give this a read: http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios.aspx

If you handle posting correctly then you'll have an Action that can accept variables and be tested a lot easier.

EDIT You can use the FormCollection param in your Action, something like this

[HttpPost]
public ActionResult Index(string btnSubmit, FormCollection collection)
{
    //btnSubmit this is the button that is clicked.
    return View();
}

The FormCollection will have everything in it from the Request.Form collection. But you should still be able to post the right hand listbox in the normal MVC way

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top