Cody
Cody

Reputation: 8964

value not being passed into partial view

For my asp.net project, I have two partial views which are displayed conditionally.

ie: if a==true, display view 1. else, display view 2.

In both of them I have a hidden variable being set in jquery

$("#hiddenVal").val($('#EmployeeSelected').val());

and then it is posted in each of the partial views:

<%: Html.Hidden("hiddenVal") %>

This works great in one, but in the other the value is "" when I use Request.Form[] The only difference I can see between the two partial view is that one inherits dynamic:

Inherits="System.Web.Mvc.ViewUserControl<dynamic>"

the other partial view (the one that DOES NOT work) inherits the model:

Inherits="System.Web.Mvc.ViewUserControl<model>

Would this make a difference in the hiddenVal?

Upvotes: 0

Views: 108

Answers (1)

griegs
griegs

Reputation: 22770

Have you tried, in your controller to do one of the following;

[HttpPost]
public ActionResult AddPosition(MyModel1 model1, MyModel2 model2)
{

Or maybe use the bind decorator;

[HttpPost]
public ActionResult ChangeDetails( [Bind(Prefix="ContactDetails")] userDetail UserDetail )
{

The reason for bind is that your controls may be being prefixed with something you are not expecting. In the sample above by controls were being prefixed with "ContactDetails.".

Also you could try using FormCollection;

[HttpPost]
public ActionResult CVMaintenance(FormCollection collection)
{

[HttpPost]
public ActionResult CVMaintenance(MyModel1 model1, FormCollection collection)
{

Upvotes: 1

Related Questions