How do I get route values from inside a View Component controller in .NET Core? -


i have view component in _layout.cshtml. application has route of /home/{id}. how can id value in url route view component controller?

public class layoutviewcomponent : viewcomponent {     public async task<iviewcomponentresult> invokeasync()     {         //how value of {id} here?          return view();     } } 

you not want view go , required parameter query string itself. strict usage of view.

instead, pass id parent.

// parent's action method public iactionresult parentactionmethod(int id) {     // use typed model     viewbag.id = 1;     return view();  }      // parent's view @await component.invokeasync("layout", new { id = viewbag.id })  // view component public class layoutviewcomponent : viewcomponent {     public async task<iviewcomponentresult> invokeasync(int id = 10)     {         return view();     } } 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -