ASP.Net MVC filters

Associate
Joined
25 Feb 2007
Posts
903
Location
Midlands
Hi,

I'm using MVC 5 and Entity Framework 6.

Say I have a Cases controller with an Index action that returns all cases to an Index view, but then I wanted to implement a My Cases feature (e.g. where case assigned to == User.Identity.Name) how would you go about this?

At the moment I've created a second action MyCases, which replicates the Index action functionality but with the added Where filter. This action still uses the Index view, just passing in an amended model object.

This works well, but I have an issue now where say I click on Edit for a Case displayed via the My Cases, the Post action redirects back to the Index action, rather than the action it came from.

I'm looking in to resolving this, but feel like I might not have implemented the MyCases feature in the best way initially! Any thoughts?
 
Soldato
Joined
27 Mar 2003
Posts
2,708
If I understand this correctly you have following uri structure:

mywebsite.com/Cases/Index
mywebsite.com/Cases/MyCases
mywebsite.com/Cases/MyCases?where=username

Both Index and MyCases are using the Index View.

If this is the case then the easiest solution would be to have two views, 1 for index and 1 for MyCases and then the common elements between these two pages (which currently is all the elements as they use one view) is then placed into a partial view and included in the views.


e.g. @Html.Partial("_myCases", model)

Then you can have the page post back to the correct action.

Alternatively if the post action should always go to the MyCases action then you can modify the BeginForm declaration @using(Html.BeginForm("MyCases","Cases",FormMethod.Post, model));

If you need some more help send me an email via trust and I will be happy to help.
 
Back
Top Bottom