Tag: #javascript

返回视图在控制器中使用警报脚本后

这是一个对在C#代码中管理JavaScript感兴趣的问题,而不是讨论这是否是一个好的设计。 我开始尝试使用此答案在控制器内创建警报。 据我所知,在控制器中使用JS并不常见。 如果我在控制器中创建警报,我如何管理程序流然后返回视图。 返回时,警报会干扰显示视图的进度。 第一种方法是在DoSomething中暂停代码: public ActionResult DoSomething() { // code to get User if(User.Role == someRole) { return Content(“alert(‘Merchant on Hold’);”); } // More code } public ActionResult Dashboard() { // Do things } 第二种方法是暂停仪表板中的代码。 public ActionResult DoSomething() { // code to get User if(User.Role == someRole) { return RedirectToAction(“Dashboard”, “AppUser”, new { […]

使用C#将函数序列化为json中的参数

我正在尝试使用C#创建在jQuery中创建对象所需的json。 json需要的是 { title: ‘title text’, upperVal: 40, lowerVal: 5, mouseover: function() { return ‘difference ‘ + (upperVal – lowerVal); } } 前几个元素很简单。 我创建了一个表示对象JSObj的类,然后通过JavascriptSerializer.Serialize()运行它 public class JSObj { public string title { get; set; } public int upperVal { get; set; } public int lowerVal { get; set; } } 这适用于前几个属性,但我不知道如何返回正确的鼠标hoverfunction。 编辑:提供的代码只是示例代码,因为我实际使用的json的结构有点复杂。 我正在使用HighCharts,我真正需要使用的配置选项之一需要一个function,即使它们不是真正有效的json( http://www.highcharts.com/ref/#tooltip–formatter )所以不幸的是我无法避免这个问题

无法找到“类型或命名空间’AjaxControlToolkit’的解决方案……”?

Error 3 The type or namespace name ‘AjaxControlToolkit’ could not be found in the global namespace (are you missing an assembly reference?) D:\My App\table\PopUpdata.aspx.designer.cs 58 27 table. 我已经声明了这个javascript但是问题是什么。

使用嵌套类创建类的Javascript JSON

我想在JavaScript中创建一个具有嵌套对象的JSON对象。 这是课程: public class CellChanged { private CellLocation _Location = null; private double _CellValue = 0; public CellLocation Location { get { return this._Location; } set { this._Location= value; } } public double CellValue { get { return this._CellValue; } set { this._CellValue = value; } } } public class CellLocation { #region Members private […]

从ASP.NET转义JavaScript特殊字符

我在ASP.NET应用程序中有以下C#代码: string script = @”alert(‘Message head:\n\n” + CompoundErrStr + ” message tail.’);”; System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), “Test”, script, true); CompoundErrStr是SQL Server生成的错误消息(从存储过程冒出的exception文本)。 如果它包含任何表列名,则它们用单引号括起来,并在执行期间中断JavaScript,因为单引号被视为字符串终止符。 作为单引号的修复,我将代码更改为: CompoundErrStr = CompoundErrStr.Replace(“‘”, @”\'”); string script = @”alert(‘Message head:\n\n” + CompoundErrStr + ” message tail.’);”; System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), “Test”, script, true); 它现在工作正常。 但是,还有其他特殊字符需要像这样转义吗? 是否有可用于此目的的.Netfunction? 类似于HttpServerUtility.HtmlEncode的东西,但是用于JavaScript。 编辑我使用.Net 3.5

在Javascript中抓取属性背后的代码?

我想将ac#code后面的属性烧成javascript警报(); 。 由于某种原因它不起作用。 有没有办法可以将codebehind属性刻录到javascript中? 谢谢

C# – 使用HTMLAgilityPack获取JavaScript变量值

我目前有2个JavaScript变量,我需要从中检索值。 HTML由一系列没有id / name属性的嵌套DIV组成。 是否可以使用HTMLAgilityPack从这些变量中检索数据? 如果是这样的话,我怎么会这样做,如果不是什么需要,正则表达式? 如果是后者,请帮我创建一个允许我这样做的正则表达式。 谢谢。 variable1 = “var1”; variable2 = “var2”;

在Web Api控制器中将JSON反序列化为字典

我有这样的JSON字符串: ‘{“1″:[1,3,5],”2″:[2,5,6],”3”:[5,6,8]}’ 我想将其发送到Web Api控制器而不使用ajax请求更改: $.ajax({ type: “POST”, url: “Api/Serialize/Dict”, data: JSON.stringify(sendedData), dataType: “json” }); 在Web Api我有这样的方法: [HttpPost] public object Dict(Dictionary<int, List> sendedData) { //code goes here return null; } 总是sendedData == null. 换句话说:我不知道如何将JSON反序列化为(Dictionary<int, List> 。 谢谢你的答案。

如何根据驻留在updatePanel中的DataGrid中的行选择更新控件?

我有一个网格[Grid1],当点击一个按钮[search]时构建它的dataRows,我设法通过将它放在UpdatePanel中进行Ajax化,它运行正常。 在对网格1进行Ajax化之前,另一个网格[Grid2]和一些其他控件[文本和标签]用于在单击网格1中的行时进行填充/更新。 Grid2和其他控件用于在网格的OnItemCommand事件上填充/更新1.ItItemCommand中的代码将相关数据绑定到Grid2和其他控件。 将Grid 1放入更新面板后,它们停止更新。 如果我将Grid2和其他控件放在同一个更新面板中,但是页面的设计方式使得我不能在与第一个Grid相同的UpdatePanel中使用这些控件,也不打算使用另一个更新面板,它将正常工作。 我希望我有所作为。 我是.Net的新手,所以请原谅。 请在下面找到代码。 <asp:ButtonColumn Text="” ButtonType=”LinkButton” HeaderText=”Add” CommandName=”Load” ItemStyle-cssClass=”Col_9_Item_2″> 后面代码中的代码停止工作 protected void grdJobs_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName == “Load”) { functionToBindDataToGrid2(); functionToBindDataToOtherControls(); } } protected void grdJobs_ItemDataBound(object sender, DataGridItemEventArgs e) { e.Item.Attributes.Add(“onclick”, “javascript:__doPostBack(‘grdJobs$ctl” + ((Convert.ToInt32(e.Item.ItemIndex + 3).ToString(“00”))) + “$ctl00’,”)”); }

“此文件被阻止,因为它来自另一台计算机” – ajax权限问题

我通过从我的网站下载的html使用jQuery ajax获取本地xml文件。 问题是每次下载文件时,用户必须右键单击它 – >属性 – >解除阻止。 否则jquery ajax会抛出“权限被拒绝”错误。 有没有办法将文件标记为可信或类似的东西? 我应该在下载文件时在服务器端实现一些东西吗? 或者在保存的html文件中在客户端添加一些东西? 提前致谢。