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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -