c# - In MVC how to go back dynamically -


in desk system creating - have view editing tickets working completely. however, after person saves edits , goes previous list view (which can 1 of 8 different views). so, found code go previous view:

<a href="javascript:void(0);" onclick="history.go(-1);">back ticket list view</a> 

which work in sense goes list view. unfortunately though when goes changes made not reflected in list view. after hit refresh correct. how make user not need hit refresh?

here edituserticket controller code:

public actionresult edituserticket(guid id)         {              var model = db.tickets                     .include(t => t.ticketnotes)                     .where(t => t.ticketid == id).first();              return view(model);         } 

you might pass return url url of ticket list view edit ticket view in form of viewmodel. editticketviewmodel should like:

public class editticketviewmodel {   public string returnurl {get;set;}   public guid ticketid {get;set;} } 

and edit method of ticketcontroller:

[httpget] public actionresult edituserticket(editticketviewmodel model) {    var model = db.tickets               .include(t => t.ticketnotes)               .where(t => t.ticketid == model.ticketid).first();    return view(model); } 

in order pass return url above controller, need embed view model in hyperlink of page provides navigation edituserticketview. replace hyperlink html helper:

@html.actionlink("hyperlinktext", "edituserticket", "yourticketcontrollername",                new editticketviewmodel                {ticketid = yourticketguid, returnurl = request.rawurl}, null); 

this partially solved problem, edituserticketview contains return url when request sent return url lost when user performs post request save data. not know whether using ajax approach in saving data or conventional synchronous post request. if conventional approach used, need pass return url in form when posting can used when redirecting edituserticketview.

and return hyperlink of edituserticketview.cshtml should like:

<a href="@model.returnurl">back ticket list view</a> 

hope helps.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -