asp.net mvc - ActionFilter to set a controller.action parameter but param req on ActionLink in View -


We have a [UserNameFilter] ActionFilterAtrribute which populates the admin action user name parameter. It works well though, when I use the Html.ActionLink assistant, the controller is strictly typed, then the user's parameters are seen in the compiler requests.

Has anyone come to this and know how to read?

Controller function:

  [UserNameFilter] Public Action Category (integer category ID, int page, string username)  

Code view :

  <% = HTML.RenderTree (ViewData.Model, i = & gt; HTML.ActionLink & lt; ProductController & gt; (PC = & gt; pc.Category (i .CategoryId, 1, ** Complaints error here **), I.CategoryName)% & gt; This is a compile time error - C # compiler knows your application, MVC or nothing. Using ActionFilter so that the user name might not be known to fill the parameter.  

The way I can think now, declaring a new action in the controller

  public functions category nozzle (int category id, int page) {string userName = "" ; / * Here the usernames are found in the action filter as you do * / Return Category (CategoryIID, Page, Username); }  

and use it in your view

If you can access the username in this view, then you can provide it for your current class action :

  & lt;% = html.RenderTree (ViewData.Model, i = & gt; HTML.ActionLink & lt; ProductController & gt; (PC = & gt; pc.Category (i .CategoryId, 1, Current User, Username), i.CategoryName)% & gt;  

Or you can enter the user name in the model:

  <% = html.RenderTree (ViewData.Model, i = & gt; HTML.ActionLink & lt; Product Controller & gt; (PC = & gt; pc.Category (i.CategoryId, 1, Model.UserName), i.CategoryName))% & gt;  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -