我想在上面的动作过滤器方法中使用动作参数。请帮帮我
Public Overrides Sub OnResultExecuted(filterContext As ResultExecutedContext)
Dim actionParameter = filterContext.ActionParameters(parameterName)
End Sub
var params={};
params.Comments=getvaluebyid("TxtComment");
$.ajax({
type: "POST",
url: '/ControllerName/ActionName',
async: true,
data: $.toJSON(params),
dataType: "json",
contentType: 'application/json; charset=utf-8',
答案 0 :(得分:0)
您可以通过以下方式获取Action参数:
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var controllerActionDescriptor = filterContext.ActionDescriptor as System.Web.Mvc.ReflectedActionDescriptor;
ParameterDescriptor[]pdes= controllerActionDescriptor.GetParameters();
foreach (var item in pdes)
{
var parameterName = item.ParameterName;
var parameterType=item.ParameterType;
}
}
要获取值,您可以这样做:
HttpContext.Current.Request.QueryString["Id"]// where "Id" is the key, you can use index here too.
希望它有所帮助!
答案 1 :(得分:0)
我找到了解决这个问题的方法。找到以下解决方案以获取json结果。对于以下方法,我们需要传递请求。
private string GetJsonContents(System.Web.HttpRequestBase Request)
{
string JsonContents = string.Empty;
try
{
using (Stream receiveStream = Request.InputStream)
{
using (StreamReader readStream = new StreamReader(receiveStream))
{
receiveStream.Seek(0, System.IO.SeekOrigin.Begin);
JsonContents = readStream.ReadToEnd();
}
}
}
catch
{
enter code here
}
return JsonContents;
}
答案 2 :(得分:0)
我遇到了同样的问题! 这是我的解决方法。
public override void OnActionExecuted(ActionExecutedContext filterContext)
{ var myValue = ((MyClass)((JsonResult)filterContext.Result).Data).Value; }
我希望这有帮助!