使用MVC3使用Ajax childactiononly属性 [英] Using MVC3 childactiononly attribute with ajax

查看:438
本文介绍了使用MVC3使用Ajax childactiononly属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ajax加载的局部视图,以添加/编辑行的剑道网格。当我preSS我想也不允许用户直接调用从浏览器的操作的行中的编辑按钮。

I am using ajax to load a partial view in order to add/edit a row in a kendo grid. When I press an edit button in the row I want to also not allow the user to directly call the Home/AddModify action from the browser.

如果我把 [ChildActionOnly] 来我的AddModify行动它不会让我加载的局部视图 因为一切都在Ajax调用,而我不希望把它在视图中的某个地方像 @ Html.Action(首页/ AddModify,模型)。我也不想从一开始加载页面时加载。

If I put [ChildActionOnly] to my "AddModify" action it does not let me load the partial view because everything is in the ajax call, and I do not want to have it in the view somewhere like a @Html.Action("Home/AddModify",model). I also do not want to load it from the beginning when the page is loaded.

我可以称之为局部视图,因此仅仅按需查看(动态)?

Can I call the partial view so it is only viewed on demand (dynamically)?

推荐答案

你需要的是一个AJAX只是attr​​ibte看看<一href="http://stackoverflow.com/questions/6558758/is-there-any-attribute-relating-to-ajax-to-be-set-for-asp-net-mvc-controller-act">this问题

What you need is an AJAX only attribte Take a look at this question

声明像

public class AjaxOnlyAttribute : ActionMethodSelectorAttribute 
    {
        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
        }
    }

和使用它像

[AjaxOnly]
public ActionResult ajaxMethod()
{

}

这篇关于使用MVC3使用Ajax childactiononly属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆