由于运行时限制,我使用的是旧版本的ASP.NET AJAX,在更新面板中放置ASP.NET验证程序不起作用.是否有一个技巧可以使这些工作,或者我需要使用AJAX工具包附带的ValidatorCallOut控件?
在为我的应用程序采用Knockout JavaScript库之前,我应该考虑哪些因素?
目前我有一个ASP.NET MVC 2站点.大多数网站的导航和设置都是简单的获取和发布操作.有些视图具有网格/多个网格,其中数据仅供查看.所有的ajax和javascript都是使用JQuery处理的.从控制器返回的JSON很少并且使用稀疏.大多数ajax网格是通过使用部分视图发送HTML来实现的.
我在使用部分回发在更新面板中动态添加控件时遇到问题.我已经阅读了很多关于动态控件的文章,我理解如何使用回发添加和维护它们,但大多数信息不适用,不适用于部分回发.我找不到有关使用UpdatePanel添加和维护它们的任何有用信息.如果可能的话,我想在不创建Web服务的情况下这样做.有没有人对某些有用的信息有任何想法或参考?
我正在使用[System.Web.Script.Services.ScriptService]标记来使用可从客户端javascript调用的Web服务.我需要的是一种全局记录这些方法中任何未处理的异常的方法.在客户端,我得到错误回调并可以从那里继续,但我需要一个服务器端catch来记录异常.
这个网址的人:http: //ayende.com/Blog/archive/2008/01/06/ASP.Net-Ajax-Error-Handling-and-WTF.aspx
表明这不可能做到.
那是准确的吗?我是否真的必须在整个系统中使用每一个web方法并尝试/捕获整个方法.
所以我有UserControl一些级联DropDownList的东西.从列表1中选择启用列表2,列表2依次启用列表3.在所有三个列表中进行选择后,您可以转到下一页.
该DropDownLists为所有内部的UpdatePanel.但是"下一页"按钮在...之外UpdatePanel.应该禁用该按钮,直到所有三个列表都有选择,然后再次启用它.但由于按钮位于按钮之外UpdatePanel,因此在进行选择时不会更新.(编辑:"下一页"按钮位于同时包含该页面的页面上UserControl.)
我知道解决这个问题的一种方法:
var scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(dropDownList1);
scriptManager.RegisterPostBackControl(dropDownList2);
scriptManager.RegisterPostBackControl(dropDownList3);
Run Code Online (Sandbox Code Playgroud)
这可以确保在更改任何下拉列表时进行回发,以便按钮可以更新.但是,如果我这样做,我可以通过UpdatePanel首先摆脱它来简化.
还有另外一种方法,通过一些聪明的JavaScript或其他东西,我可以在UpdatePanel不必放弃Ajax 的情况下更新控件吗?
我有一个用于编辑东西的视图,比如订单.订单包含可以任意添加的订单项.所以主视图和嵌套的偏见视图.
每个部分应该有一个ajax表单,用于调整每个行项目的数量或其他.
从而:
Html.BeginForm()
{%>
Ship to: blah blah blah
<%
Ajax.BeginForm("EditLineItem", "Order", new { OrderLineItemID = Model.ObjectID }, itemAjaxOptions))
{
Item qty blah blah blah
<--! (ajax form's submit button, etc.)-->
}
%>
<--! (ajax form's submit button, etc.)-->
<%
}
Run Code Online (Sandbox Code Playgroud)
我有一个看起来像这样的控制器:
[ActionName("Edit")]
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult Edit(int orderID)
{
blah, blah
}
[ActionName("EditLineItem")]
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult EditLineItem(Guid orderLineItemID)
{
blah, blah
}
Run Code Online (Sandbox Code Playgroud)
我的麻烦是,当我提交Ajax表单时,我得到Edit方法而不是EditLineItem方法.两个路由都已映射.是否有一些问题,比如"你不能在Html表单中提交Ajax表单",我不知道?
我正在清理一些遗留的框架代码,其中大量的代码只是异常编码.不检查任何值以查看它们是否为空,因此会抛出并捕获大量异常.
我有但是大多数清理,有一些错误/登录/安全相关的框架,正在做Response.Redirect的,现在,我们正在使用AJAX的方法,我们得到的ALOT 的Response.Redirect"不能被称为在页面回调中." 如果可能的话,我想避免这种情况.
有没有办法以编程方式避免此异常?我正在寻找类似的东西
if (Request.CanRedirect)
Request.Redirect("url");
Run Code Online (Sandbox Code Playgroud)
注意,这也发生在Server.Transfer上,所以我希望能够检查我是否能够执行Request.Redirect或Server.Transfer.
目前,它只是这样做
try
{
Server.Transfer("~/Error.aspx"); // sometimes response.redirect
}
catch (Exception abc)
{
// handle error here, the error is typically:
// Response.Redirect cannot be called in a Page callback
}
Run Code Online (Sandbox Code Playgroud) c# asp.net response.redirect exception-handling asp.net-ajax
以下是我目前实施的代码.
if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
{
ScriptManager scriptManager = ScriptManager.GetCurrent(page);
if (scriptManager != null && scriptManager.IsInAsyncPostBack)
{
//if a MS AJAX request, use the Scriptmanager class
ScriptManager.RegisterStartupScript(Page, Page.GetType(), scriptKey, script, true);
}
else
{
//if a standard postback, use the standard ClientScript method
Page.ClientScript.RegisterStartupScript(Page.GetType(), scriptKey, script, true);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在按照这个答案中的建议进行操作,以便我可以在两个时间注册启动脚本,即有部分回发和完整回发.
问题Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey)始终是(即使以前注册过脚本),当它是部分回发时返回false.我找不到ScriptManager.IsStartupScriptRegistered(静态)方法.因此,所有部分/异步回发都会发出附加脚本.
请注意,我正在使用AjaxControlToolkit版本4.1的脚本管理器,即ToolkitScriptManager在我的母版页中.但我不认为这与此有关.
UPDATE
<asp:UpdatePanel ID="ContactDetailsUpdatePanel" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateContactDetailsButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<div id="ContactDetailsContent" class="contact_details_content">
<div class="customer_contactdetails_left_pane">
<div class="customer_name_field">
<asp:Label ID="CustomerNameLabel" runat="server" …Run Code Online (Sandbox Code Playgroud) 我在我的控制器中声明了一个POST方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateComments(int id, string comments)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
和我认为的ActionLink:
<%= Ajax.ActionLink("update", "UpdateComments",
new { id = Model.Id, comments = "test" },
new AjaxOptions {
HttpMethod="POST",
OnFailure="alert('fail');",
OnSuccess = "alert('success');"
})%>
Run Code Online (Sandbox Code Playgroud)
尝试路由此请求时出现"未找到"错误.
如果我从控制器中的UpdateComments方法中删除POST限制,它可以正常工作.
我错过了什么?
是否有关于ASP.NET MVC 3的jQuery的书籍/教程?我需要学习如何使用ajax链接以及如何提交ajax表单等.如果没有关于MVC 3的书籍/教程,MVC 2也足够了.
PS我知道如何用MVC附带的MS AJAX Toolkit做基本的东西
asp.net-ajax ×10
asp.net ×7
c# ×5
asp.net-mvc ×2
updatepanel ×2
.net-3.5 ×1
actionlink ×1
ajax ×1
javascript ×1
jquery ×1
knockout.js ×1
routing ×1