Tag: asp.net mvc

添加jquery.unobtrusive-ajax.js引用后,Upload为null

如果我没有引用jquery.unobtrusive-ajax.js我可以在Post上获得附件。 如果我引用它它会给我null。 @using (Ajax.BeginForm(“Index”, “ContactSubmission”, new AjaxOptions{ InsertionMode = InsertionMode.Replace, HttpMethod = “POST”, OnSuccess = “updateSuccess” }, new { enctype = “multipart/form-data”,@class = “form-horizontal”, role = “form” })) { ///code here } [HttpPost] public JsonResult Index(Contact contact) { if (ModelState.IsValid) { if (contact != null) { string attachment = string.Empty; // HttpPostedFileBase Attachment if (contact.Attachment […]

使用JSON,JQuery向ASP.NET MVC Controller发布一系列复杂对象

我知道这个问题在此之前已被触及过 但解决方案似乎不适合我的问题。 这是我的HTML。 行数是可变的 Begin End js构建一个对象数组并将它们发布到控制方法中 $(function() { submitForm = function() { var items = new Array(); $(“#workPlanTable tr”).each(function(i) { var end = $(this).find(“.end”).val(); var begin = $(this).find(“.begin”).val(); var item = { “Begin”: begin, “End”: end }; items.push(item); } ); var postData = { myItems: items }; $.ajax({ url: ‘~/WorkPlan/AjaxUpdate’, type: ‘POST’, dataType: ‘json’, […]

使用jquery和ajax将json对象发布到mvc控制器

我试图从表单中提交一些值到我的mvc控制器。 这是我的控制器: //Post/ Roles/AddUser [HttpPost] public ActionResult AddUser(String json) { Log.submit(json); return View(); } 这是js: function submitForm() { var usersRoles = new Array; $(“#dualSelectRoles2 option”).each(function () { usersRoles.push($(this).val()); }); console.log(usersRoles); jQuery.ajax({ type: ‘POST’, url: “@Url.Action(“AddUser”)”, contentType: “application/json; charset=utf-8”, datatype: ‘json’, data: JSON.stringify(usersRoles), success: function (data) { alert(data); }, failure: function (errMsg) { alert(errMsg); } }); […]

MVC通过AJAX发送列表

好的,我已经看到关于这个问题的大量问题,但是没有一个答案对我有用,这是我的AJAX: $.ajax({ url: “/FilterSessions/GetFilterSession”, type: “GET”, dataType: “json”, data: jsonFilters, traditional: true, success: function (response) { //Haha, it’s never entering here. not really. } }); var“jsonFilters”包含一个包含以下数据的数组: [0] = { Path: “Test”, Name: “More testing”, Value: “Test Value” }, [1] = { Path: “Test”, Name: “More testing”, Value: “Test Value” } 这是我的控制器: public ActionResult GetFilterSession(List jsonFilters) […]

asp.net中的逗号小数分隔符mvc 5

我拼命试图让asp.net使用逗号符号作为小数分隔符,但这似乎要困难得多…… 我已经完成了本教程中的所有内容http://www.asp.net/mvc/overview/getting-started/introduction/examining-the-edit-methods-and-edit-view 在root web配置中尝试了这个 介绍了jQuery代码 – 全球化似乎有效。 我正在使用带有模型视图控制器的get请求,看起来像这样 public class SearchCalcViewModel { public SearchCalcViewModel() { } public IEnumerable Calculations { get; set; } [Display(Name=”Name”)] public string Name { get; set; } [Display(Name=”Height”)] public decimal? Height { get; set; } } 在maincontroller中调用get请求 – 这样就加强了我的假设,即jquery文化依赖validation正在工作,而.net文化中的某些东西也是错误的,即使Thread.CurrentTHread.CurrentCulture / CurrentUICulture也正确设置了。 当我尝试填充3,0作为高度时,我收到以下错误消息: 值“3,0”对高度无效。 这是我的观点的导入部分: @using (Html.BeginForm(“Search”, “Main”, FormMethod.Get)) @Html.LabelFor(m => m.Height, […]

ASP.Net MVC jQuery UI DatePicker日期格式

我最终试图强制使用这个jQuery datepicker控件来理解特定的日期格式。 这到底是怎么回事? 视图 @Html.TextBoxFor(model => model.StartDate, “{0:dd/MM/yyyy}”, new { @class = “datefield” }) 使用Javascript $(function () { $(“.datefield”).datepicker({ dateFormat: ‘dd/MM/yyyy’, showOn: “button” }); }); 在页面加载 datepicker点击,到目前为止一切顺利 选择日期……什么?

当使用jqgrid时,无论如何都有recreateForm:true但是还缓存dataUrl?

我有以下列使用jqGrid(简化) { name: “PMOPerson”, index: “PMOPerson”, width: 250, editable: true, edittype: “select”, editoptions: { dataUrl: “/Person/GetSelectData” }, editrules: { required: false} }, { name: “HeadDisplayName”, index: “HeadDisplayName”, width: 150, editable: false }, 当我通过调出编辑对话框来编辑一行时,需要10秒才能填充PMOPerson下拉列表。 甚至在我之前已经加载过一次之后就是这种情况,我认为这是因为我在下面重新创建了一个forms:true addButton({ caption: “”, title: “Edit Selected Team”, buttonicon: ‘ui-icon-pencil’, onClickButton: function () { var id = $(“#grid”).getGridParam(“selrow”); if (id) { jQuery(“#grid”).jqGrid(‘editGridRow’, […]

防止双重提交

我有一个ASP.NET MVC 3应用程序,它有一个名为Create的后置操作: [HttpPost] public virtual ActionResult Create(Issues issues) { if (ModelState.IsValid) { context.Issues.Add(issues); context.SaveChanges(); return RedirectToAction(“Index”); } return View(issues); } 如果我错误地双击提交按钮,它将创建2x问题。 有没有办法防止这种情况,没有使用javascript和禁用按钮,我认为使用RedirectToAction的全部用途是通过使用Post / Redirect / Get设计模式来防止这种情况?

在MVC 4中增加json响应maxJsonLength

我在razor视图引擎MVC4(.net 4.5)应用程序中加载大型JSON响应表单服务器时遇到以下错误 “ 使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过@ Html.Raw(Json.Encode(jsondata ) 上的maxJsonLength属性上设置的值 ” 我试过在我的web.config中设置MaxJsonLength属性: configuration> 在发送JSON响应的同时在服务器端尝试跟踪。 return new JsonResult() { Data = data, ContentType = contentType, ContentEncoding = contentEncoding, JsonRequestBehavior = behavior, MaxJsonLength = Int32.MaxValue }; 还尝试了列出的解决方案: http : //brianreiter.org/2011/01/03/custom-jsonresult-class-for-asp-net-mvc-to-avoid-maxjsonlength-exceeded-exception/ 。 但没有什么对我有用:( 有人可以建议我如何避免这个错误或如何增加杰森响应最大长度?

从chrome 中的日期类型输入中删除占位符

我有以下输入: 这会将日期格式显示为默认占位符。 我想删除这个占位符,只有一个空输入字段。 如果我这样做: `$(‘#operationDate’).val(‘@DateTime.Now.ToString(“yyyy-MM-dd”)’);` 我今天的日期是占位符,但是如果我使用它: $(‘#operationDate’).val(”); 我得到像dd-mm-yyyy这样的占位符。 占位符可以被彻底删除吗? 我已经看过几篇关于更改日期格式的post,但是没有找到关于删除占位符的信息。