asp.net mvc 3 ajax 表单在 telrik Grid 中提交时打开一个新页面

发布于 2024-12-20 08:48:43 字数 1686 浏览 4 评论 0原文

在我的 ASP 中。 Net MVC 3.0 项目。 我有 Telerik 网格。

在网格单元中,我从部分视图加载内容,其中包含 Ajax 表单。 (对于网格一列中的每个单元格)

当我提交该表单时。

Ajax 表单打开新页面而不是更新目标 ID。

我正在加载所需的脚本

<script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>

这些脚本加载在母版页 (_Layout.cshtml)

我的 Web.config

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

我在这个项目的大部分地方都使用了 Ajax 表单。 它在所有这些地方都很完美。

如果我可以从 Telerik 网格提交 ajax 表单,有任何线索

更多详细信息

控制器

public JsonResult AddRemoveThisLocation(int LocationID, FormCollection collection, string button)
    {
return Json(new
        {
            success = _success,
            message = _message
        }, JsonRequestBehavior.AllowGet);
    }
 }

部分视图使用 .loadContentfrom() 方法加载到 Telerik 网格

@using(Ajax.BeginForm("AddRemoveThisLocation", "Controller", new { LocationID = Model.AddressID }, new AjaxOptions {
OnBegin="ValidateNumbers",
HttpMethod = "POST",
OnSuccess = "ShowSignUpStatus"} ))
{
 @Html.TextBoxFor(model => model.Phone, new { id="phone"+Model.AddressID, name="Phone" })
<input type="submit" value="Add" class="button" name="button" id="@(Model.AddressID)" />
}

in my ASP. Net MVC 3.0 Project.
I have Telerik Grid.

with in the grid cell I am loading content from partial view with a Ajax Form in it.
(for each Cell in one column of the grid)

when i submit that form.

Ajax form is opening new page instead of updating the target ID.

I am loading the required scripts

<script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>

These scripts are loaded on master page (_Layout.cshtml)

My Web.config

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

I have used the Ajax forms at most of the places in this project.
It works perfect at all those places.

Any clue if i can submit ajax form from a telerik grid

More Details

Controller

public JsonResult AddRemoveThisLocation(int LocationID, FormCollection collection, string button)
    {
return Json(new
        {
            success = _success,
            message = _message
        }, JsonRequestBehavior.AllowGet);
    }
 }

Partial View loaded in to the Telerik Grid using .loadContentfrom() method

@using(Ajax.BeginForm("AddRemoveThisLocation", "Controller", new { LocationID = Model.AddressID }, new AjaxOptions {
OnBegin="ValidateNumbers",
HttpMethod = "POST",
OnSuccess = "ShowSignUpStatus"} ))
{
 @Html.TextBoxFor(model => model.Phone, new { id="phone"+Model.AddressID, name="Phone" })
<input type="submit" value="Add" class="button" name="button" id="@(Model.AddressID)" />
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别闹i 2024-12-27 08:48:43

我有类似的问题。解决方案是确认没有重复的 jQuery 引用
并检查这些是否正确加载。

    <script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

这应该可以解决你的问题。

I had similar problem. adn the solution is confirm no repeated jQuery References
and check if these are loadin correctly.

    <script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

That should fix your problem.

睫毛溺水了 2024-12-27 08:48:43

试试这个:

 [AcceptVerbs(HttpVerbs.Post)]
 public JsonResult AddRemoveThisLocation(int LocationID, FormCollection collection, string button)
        {
    return Json(new
            {
                success = _success,
                message = _message
            }, JsonRequestBehavior.AllowGet);
        }
     }

Try this:

 [AcceptVerbs(HttpVerbs.Post)]
 public JsonResult AddRemoveThisLocation(int LocationID, FormCollection collection, string button)
        {
    return Json(new
            {
                success = _success,
                message = _message
            }, JsonRequestBehavior.AllowGet);
        }
     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文