Tag: c#

将Json对象从Asp.net webMethod返回到Ajax调用

我有以下Ajax调用方法和asp.net webmethod。 我的asp.net函数返回一些我在Ajax调用中需要的值。 我已经尝试过很多东西,但还没有成功。 AJAX CALL $(document).ready(function () { // Add the page method call as an onclick handler for the control. $(“#”).change(function () { debugger; var myparam = $(“#”).val(); //id name for dropdown list $.ajax({ type: “POST”, url: “FileTax.aspx/ddlEmailTemplate_SelectedIndexChanged”, data: ‘{param:”‘ + myparam + ‘”}’, contentType: “application/json; charset=utf-8”, success: function (data) { alert(data.d) } […]

如何通过jquery ajax发送AntiForgeryToken(CSRF)和FormData

所以我想通过AJAX与AntiForgeryToken一起AntiForgeryToken fileUpload。 这是我的代码: 视图 @using (Html.BeginForm(“Upload”, “RX”, FormMethod.Post, new {id = “frmRXUpload”, enctype = “multipart/form-data”})) { @Html.AntiForgeryToken() @Html.TextBoxFor(m => m.RXFile, new {.type = “file”}) …rest of code here } $(document).ready(function(){ $(‘#btnRXUpload’).click(function () { var form = $(‘#frmRXUpload’) if (form.valid()) { var formData = new FormData(form); formData.append(‘files’, $(‘#frmRXUpload input[type=”file”]’)[0].files[0]); formData.append(‘__RequestVerificationToken’, fnGetToken()); $.ajax({ type: ‘POST’, url: ‘/RX/Upload’, […]

在具有大量数据的mvc4中的ajax发布期间,系统抛出System.ArgumentExceptionexception

我正在做一个ajaxpost来发布mvc4中javascript的数据,但它失败并出现以下exception string exceeds the value set on the maxJsonLength property. Parameter name: input System.ArgumentException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. 我已经尝试在Web配置中设置配置,但它无法正常工作 我也试过下面的链接,但没有任何作用: http : //forums.asp.net/t/1751116.aspx?How+to+increase+maxJsonLength+for+JSON+POST+in+MVC3 var editorText = eval(htmlEditor).GetHtml(); $.ajax({type: ‘POST’, cache: false, contentType: ‘application/json; charset=utf-8’, url: “../Home/SaveExceptionLetter”, data: […]

使用HttpResponseMessage 401在ajaxpost上取得成功

我总是在客户端的ajaxpost上获得statusCode=200 ,而服务器使用HttpStatusCode.Unauthorized回答。 我的控制器代码: public class AccountApiController : ApiController { public HttpResponseMessage Login(HttpRequestMessage request, [FromBody]LoginViewModel loginModel) { return request.CreateErrorResponse(HttpStatusCode.Unauthorized, “Unauthorized login.”); } } 我的ajax代码: $.ajax({ url: ‘/api/accountapi/login’, type: ‘POST’, data: data }) .done(function (object, status, xhr) { alert(“Success: ” + xhr.status + ” : ” + xhr.statusText); }) .always(function (object) { $(“#output”).text(JSON.stringify(object, null, 4)); }); 结果:带文本警报Success: […]

在MVC4中仅刷新部分视图

我在刷新mvc4的部分视图时遇到了一些麻烦,下面是代码: $(function() { $(“#firstPartialLink”).click(function() { $(“#partialViewDiv”).load(‘@Url.Action(“GetDiv”, “Home”)’); }); $(“#secondPartialLink”).click(function () { $(“#partialViewDiv”).load(‘@Url.Action(“GetDiv2”, “Home”)’); }); }) 当我第一次按下其中一个按钮时,它会在DIV中呈现部分视图,但是当我再次按下它时,没有任何反应,原因是什么?

在asp.net中使用进度条

我使用了这个链接中给出的例子 这是我的.aspx页面的代码 $(document).ready(function() { $(“#progressbar”).progressbar({ value: 37 }); }); 并且进度条的div就是这个 我试图按照源页面上给出的说明但没有任何效果。 你能告诉我我在这里失踪了吗? 提前。 (修正了这部分。我在放置我的contntentplaceholder时犯了一个错误) 编辑:我怎么能以某种方式更改值,以便在按下按钮时动画…按钮的页面代码如下:

如何在MVC上移动两个列表框之间的项目 – JQuery无法正常工作

我已经查看了其他SO主题,他们最终要么真的老了,要么使用WebForms。 我有一个MVC视图,其中我有两个列表框。 我想在两个列表框之间来回移动项目。 观点是: @using (Html.BeginForm()) { @Html.ListBoxFor(m => m.SelectedAttributes, Model.Attributes, new {id=”listBoxAvail”, SIZE = 5} ) @Html.ListBoxFor(m => m.SelectedAttributes2, Model.SelectedItems, new { id = “listBoxSel”, SIZE = 5}) } ViewModel是: public class OptInViewModel { public IEnumerable SelectedAttributes { get; set; } public IEnumerable SelectedAttributes2 { get; set; } public IEnumerable Attributes { get; set; […]

回发后,我的JavaScript函数在ASP.NET中不起作用

我有常见的function,我在Scripts文件夹中的CommonFunctions.js其折叠。 我将它包含在我的母版页上并在我的页面上使用它。 当我在页面上发回任何post时,我的function不起作用。 我的CommonFunctions.js : $(function () { gf(); if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) { gf(); } function gf(){ $(‘.AddNewGeneralPanel’).click(function () { if ($(this).find(‘.AddNewGeneralPanelStyle’).text() == “”) { $(this).find(‘.AddNewGeneralPanelStyle’).text(“( Gizle )”); lastOpenId = $(this).attr(“kodid”); } else $(this).find(‘.AddNewGeneralPanelStyle’).text(“”); $(this).next(‘.AddNewGeneralAccordionDiv’).slideToggle(‘slow’, function () { }); }); } });

关闭浏览器时,自动从ASP.NET中的表单身份validation注销

当浏览器关闭或用户输入新地址时,有没有办法强制ASP.NET从其身份validation中退出? 如果浏览器保持打开状态,那么我需要对用户进行身份validation,因此最好在身份validation票证上超时。

如何通过asp.net mvc中的自定义jQueryvalidation复选框列表

我有一个复选框列表,我想在客户端使用jQueryvalidation但失败。 我已经在我的项目中添加了不显眼和jqueryvalidation插件。 型号代码是: [Required] public string name { get; set; } [SkillValidation(ErrorMessage = “Select at least 3 skills”)] public List skills { get; set; } 和其他模型是: public class CheckBox { //Value of checkbox public int Value { get; set; } //description of checkbox public string Text { get; set; } //whether the checkbox is selected […]