你可以这样做:

public static class AjaxExtensions

{

public static IHtmlString DefaultLink(this AjaxHelper helper,string text,string action,string controller,string updateTargetId = "",string onSuccess = "")

{

// Build your link here eventually using

// the arguments passed

var options = new AjaxOptions

{

OnSuccess = onSuccess,UpdateTargetId = updateTargetId,OnFailure = "handleError",LoadingElementId = "loading"

// etc...

}

// return a normal ActionLink passing your options

return helper.ActionLink(text,action,controller,options);

}

}

注意我在签名中使用可选参数从多重重载的灵活性中受益,而不会妨碍它们的维护.根据需要展开:)

然后使用它如下:

@Ajax.DefaultLink("home",updateTargetId: "content")

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐