Jquery 为什么我的ActionFilterAttribute没有在发布ajax请求之前执行?
我尝试在控制器上使用重写OnActionExecute,以便在使用jQuery.post从post接收的模型中插入其他值,但在这种情况下,OnActionExecute在我的保存操作之前没有被调用。是否有一种方法可以在后期操作之前更改收到的模型 这是我的OnActionExecuting示例:Jquery 为什么我的ActionFilterAttribute没有在发布ajax请求之前执行?,jquery,ajax,asp.net-mvc-4,entity-framework-5,action,Jquery,Ajax,Asp.net Mvc 4,Entity Framework 5,Action,我尝试在控制器上使用重写OnActionExecute,以便在使用jQuery.post从post接收的模型中插入其他值,但在这种情况下,OnActionExecute在我的保存操作之前没有被调用。是否有一种方法可以在后期操作之前更改收到的模型 这是我的OnActionExecuting示例: protected override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContex
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.ActionParameters.ContainsKey("model") || filterContext.ActionParameters.ContainsKey("Model"))
{
var result = filterContext.ActionParameters["model"] as Apoio;
if (result != null) result.StringProperty = "value of string property";
}
}
这对我来说是必要的,因为我的模型有关系1:N,如下所示:
行动:
型号:
public class Model
{
public int Id { get; set; }
public string StringPropert { get; set; }
private ICollection<ModelChild> _listChild;
public ICollection<ModelChild> ListChild {
get
{
if (!string.IsNullOrWhiteSpace(StringProperties))
{
var modelChild = new ModelChild(StringProperty);
var list = (from item in model.GetAllChilds(StringProperty).Where(item => item .MasterId == this.Id) select item).ToList();
return list;
}
return _listChild;
}
}
}
public class ModelChild
{
public int Id { get; set; }
public string StringPropert { get; set; }
public int MasterId { get; set; } // <== reference to Model.Id
}
有人有主意吗?
谢谢
public class Model
{
public int Id { get; set; }
public string StringPropert { get; set; }
private ICollection<ModelChild> _listChild;
public ICollection<ModelChild> ListChild {
get
{
if (!string.IsNullOrWhiteSpace(StringProperties))
{
var modelChild = new ModelChild(StringProperty);
var list = (from item in model.GetAllChilds(StringProperty).Where(item => item .MasterId == this.Id) select item).ToList();
return list;
}
return _listChild;
}
}
}
public class ModelChild
{
public int Id { get; set; }
public string StringPropert { get; set; }
public int MasterId { get; set; } // <== reference to Model.Id
}