Reputation: 10364
In my index
view I have a filter called currentFilter
which I am passing to my edit
view through the ViewBag
like so:
@Html.ActionLink("Edit", "Edit", new { evpId = item.EvpId, currentFilter = ViewBag.CurrentFilter })
In my edit view I have 3 submit buttons like so:
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input id="btnSubmitSave" type="submit" name="submitButton" value="Save" class="btn btn-default cancel" />
<input id="btnSubmitResolve" type="submit" name="submitButton" value="Resolve" class="btn btn-default" />
<input id="btnSubmitUnResolvable" type="submit"name="submitButton" value="UnResolvable" class="btn btn-default cancel" />
</div>
</div>
</div>
Then finally in my controller I am doing a switch which redirects to the appropriate Post action for each button.
[HttpPost]
public ActionResult Edit(string submitButton, PersonViewModel modifiedPersonViewModel)
{
switch (submitButton)
{
case "Save": return (Save(modifiedPersonViewModel));
case "Resolve": return (Resolve(modifiedPersonViewModel));
case "UnResolvable": return (UnResolvable(modifiedPersonViewModel));
default: return (View());
}
}
I want to pass the currentFilter
value through with my button click, as currently if they click save for example, when they return to the index
view the filter is lost and they must type it in again, I just don't get how to pass this though an input tag?
Upvotes: 0
Views: 4836
Reputation: 8197
You can insert input with type hidden
in your form:
<input type="hidden" name="currentFilter" value="@Model.CurrentFilter" />
<input id="btnSubmitSave" type="submit" name="submitButton" value="Save" class="btn btn-default cancel" />
<input id="btnSubmitResolve" type="submit" name="submitButton" value="Resolve" class="btn btn-default" />
<input id="btnSubmitUnResolvable" type="submit"name="submitButton" value="Unresolvable" class="btn btn-default cancel" />
You'll need to append CurrentFilter
property to Edit model.
Then you can use this value in the action:
public ActionResult Edit(string currentFilter, string submitButton, PersonViewModel modifiedPersonViewModel)
{
...
}
Upvotes: 2