Ajax Form URL from List<ViewModel>
-
My page has a model type of List. I am looping through that list and generating a form for each item. The items are all available reports, some of which accept parameters, some don't. As such, I decided to build a form for each one and handle the parameter processing on the controller end. Here is what the code looks like, sorta:
@foreach(ViewModels.ReportViewModel item in Model) {
* class="k-state-active"}}>
class="k-link k-state-selected"}}>@item.name@using (Ajax.BeginForm("Queue","Reporting",options)) { @Html.HiddenFor(t => item.id) @Html.Hidden("id",item.id) foreach(var parameter in item.parameters) { @Html.Label(parameter.displayName) @Html.EditorFor(p => parameter.name, "ECR") } <input type="submit" class="k-button k-button-icontext k-grid-select" style = "margin-left:255px;width:50px" id="submit" name="submit" value="Submit" /> } i++; }
And the controller code looks like this:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Queue(ReportViewModel vm)
{
ReportQueue item = new ReportQueue
{
reportId = vm.id,
userId = 2,
statusId = 0,
reportParams = null,
datestamp = DateTime.Now
};
_uw.ReportQueueRepository.Insert(item);
_uw.Save();return RedirectToAction("Index", new { id = vm.claimId }); }
The rendered form markup looks ok (action: /Reporting/Queue) but it is not hitting the action on the controller but is actually making a mess. Firebug shows it trying to process an Ajax request for data (Which is expected as the parameter.name triggers an editor template) but it is appending /Queue onto the Ajax request. What gives