而converter=new ReflectedParameterDescriptor(parameterInfo, this),ReflectedParameterDescriptor构造函数如下: public ReflectedParameterDescriptor(ParameterInfo parameterInfo, ActionDescriptor actionDescriptor) { ParameterInfo = parameterInfo; _actionDescriptor = actionDescriptor; _bindingInfo = new ReflectedParameterBindingI...
注意观察,我们需要将参数名对应到路由中,即此处的id和run,参数如上述action参数列表 context.MapRoute("student_new","student/{controller}/{action}/{id}/{run}",new{ action ="Index", id = UrlParameter.Optional, run =UrlParameter.Optional } ); context.MapRoute("student_default","student/{controll...
我们利用MethodInfo的声明类型得到Controller的类型,将剔除“Controller”后缀的类型名称作为ControllerName属性(表示Controller的名称),作为Action名称的ActionName属性则直接返回方法名称。Parameters属性返回一个ParameterDeor数组,而根据ParameterInfo对象构建的ParameterDeor是对参数的描述。 publicclassActionDeor { publicMethodInfo ...
DefaultApplicationModelProvider会为Action方法的每个参数创建一个ParameterModel对象,并添加到Parameters属性中。应用在Action方法上的用于封装路由信息(特性路由、约束和终结点元数据)的SelectorModel对象会按照上述的方式构建出来,并添加到Selectors属性中。标注在Action方法上的特性会被提取出来并添加到Attributes属性返回的列表...
clientId=context.HttpContext.Request.Query[ParameterName]; break; caseClientIdSource.Body: //使用反射从请求体中读取client_id //这里读取到的body是Controller下Action方法的第一个参数,通常是请求体中的JSON数据模型绑定转换为对应DTO实例 varbody=context.ActionArguments.Values.FirstOrDefault; ...
(ParameterInfo parameterinmethod.GetParameters())13:{14:parameters.Add(this.ModelBinder.BindModel(controllerContext,parameter.Name,parameter.ParameterType));15:}16:ActionResult actionResult=method.Invoke(controllerContext.Controller,parameters.ToArray())asActionResult;17:actionResult.ExecuteResult(controllerContext...
[ActionName("Index")] public IActionResult Index() { return View(); } [ActionName("Index With Parameter")] public IActionResult Index(string text) { return View(); } 再次运行程序,一切都是ok的,没有任何编译时或者运行时错误,截图如下: ...
public static bool HasParameter<T> (this Microsoft.AspNetCore.Mvc.ApplicationModels.ActionModel action, string parameterName); 类型参数 T 参数类型。 参数 action ActionModel 给定的操作模型。 parameterName String 给定的参数名称。 返回 Boolean True/False。 适用于 产品版本 OData Web API ...
Without known conditions to safeguard against, returning a specific type could suffice. The preceding action accepts no parameters, so parameter constraints validation isn't needed. When multiple return types are possible, it's common to mix anActionResultreturn type with the primitive or complex retu...
parameter values for the action method, based on theRouteDatainstance and based on the form data. If the parameter value cannot be parsed, and if the type of the parameter is a reference type or a nullable value type, null is passed as the parameter value. Otherwise, an exception is ...