In my model I have these properties,
public string[] SelectedIDs {get; set;}
public int BookId {get;set;}
public int LanguageId {get;set;}
In my view I have the following,
@Html.HiddenFor(model => model.SelectedIDs )
@Html.HiddenFor(model => model.BookId )
@Html.HiddenFor(model => model.LanguageId )
Using a JavaScript array (SelectedItemIds) I am updating the SelectedIDs,
$a("#SelectedIDs").val(SelectedItemIds.join());
alert($a("#SelectedIDs").val());
The alert successfully returning comma separated values.
If I do a post
to my action no problem, I am getting the SelectedIDs
as comma seperated. However my requirement was to populate the view in a dialog, However while passing I am always getting SelectedIDs
as null.
I tried with two of the following methods.
Method 1:
My action is:
public ActionResult MyMethod1(MyModel model)
{
}
And I used the action link as
@Html.ActionLink("My Book", "MyMethod1", "BookOrder", new { @id = "SubmitBooks", @class = "subBook", data_dialog_id = "AddBookDialog", data_dialog_title = "Add Books", data_dialog_width = 800, data_dialog_height = 550 })
In this method I successfully get model.BookID
as well as model.LanguageId
, but model.SelectedIDs
was null
.
Method 2:
My action is:
public ActionResult MyMethod2(string[] selectedItems, int bookId, int langId)
{
}
And I used the action link as
@Html.ActionLink("My Book", "MyMethod2", "BookOrder", new { @selectedItems= Model.SelectedIDs , @bookId= Model.BookId, @langId = Model.LanguageId }, new { @id = "SubmitBooks", @class = "subBook", data_dialog_id = "AddBookDialog", data_dialog_title = "Add Books", data_dialog_width = 800, data_dialog_height = 550 })
Here too I got both bookid
and langId
but no selectedItems
, which is null
.