views:

37

answers:

2

Hi All,

Is there a way to stuff my ViewModel into an Ajax.ActionLink?

edit I'd like to take my 5 search fields on my page which are bind to a view model and send it along my .ActionLink as my object value parameter.

Thanks, rod

A: 

This will create a link with url parameters from your model:

<%= Ajax.ActionLink("Link Text", "View", "Controller", new { urlParam = Model.Param1, urlParam2 = Model.Param2}, new AjaxOptions() ) %>
Steve Horn
But it won't account for changes the user might introduce in the search text fields once the view has been rendered.
Darin Dimitrov
A: 

Instead of using Ajax.ActionLink, can't you use a normal submit button inside your form? You could even style it as a link if you use <input type="image" .... This way when the user clicks on the button it will submit the whole form together with the search values. Then ajaxify the form with Ajax.BeginForm.

To avoid polluting your markup with javascript, I would strongly recommend you using the more unobtrusive jQuery framework instead of Microsoft Ajax.

Darin Dimitrov
@Darin - Currently the form is posting back for the search page to retrieve results for a paged grid (Which doesn't have all the records for an export to Excel which is also an option on the page). The form I'm using is <% Ajax.BeginForm %> and I can't get the file download dialog for the export due to, I guess, the UpdateTargetId of the form. There in lies my issues.
rod