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
Post a Comment