Asp.NET MVC ActionFilter cannot get Form Submit data -


I want to use custom action filter to manipulate the criteria in an action.

User information: 2 names in a form;

Action: Actually need to take 2 IDs;

Actions filter (execution will confirm, input names and if valid, change them to 2 ID and change them to Routedata)

Because I do not have the validation logic in the action controller Want to keep

Routing information {/ p>

Routes ("default", // root name "{controller}"

New {controller = "home", action = "index"} / / parameter defaults) with / {action} ", // URL parameter;

Routes. New (Controller = "Relationship", Action = "Result"}) with Margaret ("Relationship Relationships", // Root Name "Relationships / {initPersonID} / {targetPersonID}", // parameters;);

  • Form for submitting (2 input box and submit via jquery)

    & lt;% (Html.BeginForm ("Results "," Relationship ", FormMethod.Post, new {id =" formSearch "})) {%>
    ...

      & lt; Td align = "left" & gt; & Lt;%: MvcWeibookWeb.Properties.Resource.Home_InitPersonName% & gt; & Lt; / Td> & Lt; Td align = "right" & gt; & Lt;% = Html.TextBox ("initPersonID")%> & Lt; / Td> & Lt; Td rowspan = "3" valign = "top" & gt; & Lt; Div id = "sinaIntro" & gt; & Lt;%: MvcWeibookWeb.Properties.Resource.Home_SinaIntro% & gt; & Lt; Br / & gt; & Lt;%: MvcWeibookWeb.Properties.Resource.Genearl_PromotionSina% & gt; & Lt; / Div & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td align = "left" width = "90px" & gt; & Lt;%: MvcWeibookWeb.Properties.Resource.Home_TargetPersonName% & gt; & Lt; / Td> & Lt; Td align = "right" & gt; & Lt;% = Html.TextBox ("targetPersonID")%> & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td colspan = "2" align = "right" & gt; & Lt; A href = "#" class = "btn-home search" onclick = "$ ('# formSearch'). Submit ();" & Gt; & Lt;%: MvcWeibookWeb.Properties.Resource.Home_Search% & gt; & Lt; / A & gt; & Lt; / TD & gt;  
  • Action Filter

      Public Override Zero Onnection Execution (Action Accepting Contact Filter, Contex) {Sina. Search searcher = new Sina. Seeker (Sina .Processor.UserNetwork); String initPersonName, targetPersonName; // Form submit name, we need to process them and change them to ID before entering the actual controller. InitPersonName = filterContext.RouteData.Values ​​["initPersonID"] as string; TargetPersonName = filterContext.RouteData.Values ​​["targetPersonID"] as a string; // Asset AD to convert it and  
  • Action / Controller

    [ValidationActionFilter] [Handler] Public Actioners Results Results (Int. 64 InitPersonID, Int64 targetPersonID) {...

  • My problem is: Filter in action, this never returns 2 parameters "initPersonID" and "targetPersonID", RootData. Prices are not the 2 keys ...

    : (

  • The problem is Since there are no values ​​for your passwords in initPersonName and targetPersonName , they are never lost in your route data. Try it (though it seems a bit weird ):

      initPersonName = filterContext.RouteData.Values ​​["initPersonID"] as string; targetPersonName = filterContext.RouteData.Values ​​["targetPersonID"] in the form of a string;  

    Since "... ID" Where are called, what you see in your route data. The fact that you are not actually include ID in the URL for another thing ...


    Comments