Ajax.BeginForm不正确发布 [英] Ajax.BeginForm doesn't post properly

查看:119
本文介绍了Ajax.BeginForm不正确发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的要求,我似乎无法满足:我有一个产品页面。产品有供应商和供应商输入与自动完成的文本字段。如果用户输入不存在于数据库中的供应,我需要添加它。与呼叫添加它,我有我.load页面(在DIV)我/供应商/创建控制器的方法。认为该方法使用:

I have a simple requirement I seem unable to meet: I have a product page. products have vendors and the vendor input is a text field with an autocomplete. if the user enters a vendor that doesn't exist in the database, I need to add it. to add it I have a DIV on the page which I .load() with a call to my /Vendor/Create controller method. the view for that method uses:

@using (Ajax.BeginForm("Create", "Vendor", new AjaxOptions {
     UpdateTargetId = ViewBag.TargetId,
     HttpMethod = "Post", 
     OnSuccess="VendorCreated", 
     OnComplete="alert('success')"
})) {

这应该通过AJAX后我的形式,调用Javascript的完成时。我遇到的问题是,在提交我的整个页面被刷新,这样我结束了/供应商/创建时,我开始用/产品/创建。此外,无论是的onSuccess也没有的onComplete调用。

which should post my form via ajax, calling Javascript when done. The problem I'm having is that upon submission my whole page gets refreshed such that I end up with /Vendor/Create when I started with /Product/Create. additionally, neither the OnSuccess nor OnComplete get called.

我在做什么错在这里?

推荐答案

请确保你已包括以下脚本到你的网页:

Make sure you have included the following scripts to your page:

jquery-1.5.1.js
jquery.unobtrusive-ajax.js

和那个不显眼的JavaScript是在web.config中启用:

and that unobtrusive javascript is enabled in web.config:

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

这篇关于Ajax.BeginForm不正确发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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