Tag: asp.net mvc 4

将checkBox的值传递给asp.net mvc4中的控制器操作

我想测试是否从我的acion methon中选中了复选框,我需要的是将复选框值从视图传递给控制器 这是我的看法 @using (Html.BeginForm(“Index”, “Graphe”)) { Responsable: Selectionnez — 我试着这样做: public ActionResult Index( string responsables, bool checkResp) { Highcharts chart = new Highcharts(“chart”); if (responsables != null) { if (checkResp) chart = Global(); else chart = Resp(responsables); } else chart = Global(); return View(chart); } ,但我有这个错误: Le dictionnairedeparamètresconientuneentréeNullpourleparamètre«checkAct»de type non Nullable«System.Boolean»pourlaméthode«System.Web.Mvc.ActionResult Index(System.String,System.String,Boolean)»dans«Project .Controllers.GrapheController»。 Unparamètrefacultatifdoitêtreuntyperéférence,un […]

asp.net mvc @ Html.CheckBoxFor

我的表格中有复选框 我添加了我的模型 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CorePartners_Site2.Models { public class CareerForm { //…. public List EmploymentType { get; set; } } } public class CheckBoxes { public string Text { get; set; } public bool Checked { get; set; } } 并在我的表格中添加 @Html.CheckBoxFor(model => model.EmploymentType, new { id = “employmentType_1” […]

ASP.NET MVC自定义错误

我的目标是在应用程序中创建一个处理所有托管错误的error handling,而不仅仅是与MVC相关。 所以我没有使用HandleErrorAttribute模式,因为它仅用于MVC错误,而不是其他托管错误。 在我的Global.asax中我有: protected void Application_Error() { string displayError = ConfigurationManager.AppSettings[“DisplayError”]; NameValueCollection serverVariables; int loop1, loop2; StringBuilder serverVariableKeys = new StringBuilder(); Exception exception = Server.GetLastError(); HttpException httpException = exception as HttpException; if (HttpContext.Current != null) { // loop through and get server vars } if (exception != null) // Log Error // Redirect to […]

使用MVC Razor传递列表对象

我正在使用一个对象但在对象内部我有一个属性是一个对象列表。 我希望将该对象与其中的列表对象一起传递,但是当我提交表单时列表为空。 我不知道如何处理这个问题。 类 public class VSTAttendance { public int MemberID { get; set; } public string Name { get; set; } public string Surname { get; set; } public bool Attendant { get; set; } } public class ServiceAttendance { public int AttendanceID { get; set; } public int AttendanceTypeID { get; set; } […]

上传mvc文件时在浏览器中刷新c#

我通过调用MVC C#驱动程序上传了一个AJAX文件,但浏览器刷新并重新加载页面。 但是,如果我注释在驱动程序中保存文件的行不会发生,只有当文件保存在服务器上时才会发生。 File.SaveAs (fname); MVC控制器: [HttpPost] public ActionResult UploadDocument() { if (Request.Files.Count > 0) { try { FileUpdateDto fileModal = new FileUpdateDto(); HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; string fname; DirectoryInfo directory = new DirectoryInfo(Server.MapPath("~/Content/Document/" + UserId).ToString()); if (!directory.Exists) { Directory.CreateDirectory(Server.MapPath("~/Content/Document/" + […]

如何在MVC 4中的同一视图中打开窗口?

我在视图中有一个Telerik MVC网格,带有“下载”自定义按钮。 此按钮重定向到我的下载操作,此下载操作将我重定向到下载视图,该视图以窗口模式显示一些图像。 我想在同一页面打开这个窗口,网格’在’下面。 我的代码: c.Bound(column => column.IsStock); c.Bound(column => column.Version); c.Command(cmd => cmd.Custom(“Download”) .Text(“Download”) .DataRouteValues(d => { d.Add(k => k.IDDocument); d.Add(k => k.ReceivedDate); }) .SendDataKeys(true) .Action(“Download”, “Administrative”)); 行动: [Authorize(Roles = “Administrator, Employee”)] public ActionResult Download(DocumentModel model) { var listUris = new List(); var uris = ServiceProxy.GetInstance().GetContainerUri(model.IDProtocol.ToString(), model.IDDocument.ToString())); foreach (var uri in uris) { listuris.Add(uri.AbsoluteUri); […]

使用无效变量名称的jQueryvalidation远程:如何修复?

我正在使用jQuery Validation进行远程validation。 我试图在MVC中调用我的服务器端代码,但问题是我的变量是在嵌套类中: public class Customer { public State HouseState {get;set;} } public class State { public string Name {get;set;} } 在我的* .cshtml中我有这个: @Html.TextBoxFor(m => m.HouseState.Name, new { placeholder = “State Name”}) 我正在添加validation: $.validator.addMethod(“verify”, verify); $(‘#HouseState_Name’).rules(‘add’, { verify: true, remote: ‘@Url.Content(“~/Home/Validate”)’, messages: { verify: “No!” } }); 在这种情况下,它将生成如下的GET请求: http://localhost/Home/Validate?HouseState.Name=CA 问题是它希望我的服务器中的变量是House.Name是C#中无效的变量名。 有没有办法在客户端中自定义此变量或为服务器中的变量创建别名? 我已经尝试过使用FormCollection并且它有效,但远非完美。 public JsonResult Validate(FormCollection […]

返回模型以使用selectlistitem默认值查看错误

我有一些问题与我的下拉列表的默认值在返回我的模型以查看一个或多个错误时。 我在视图中有一个下拉列表,它从控制器和同一视图中的其他空下拉列表中填充,在第一个下拉列表的选择中填充了JSON。 public ActionResult Countriesdata() { CountrydetailsViewModel vm= new CountrydetailsViewModel(); vm.countries= dal.countries().Select(x => new SelectListItem { Text = x.Name, Value = x.CountryID.ToString() }) .ToList(); return View(vm); } 这里,dal是我的数据访问层,允许我从数据库中填写国家列表。 用于填充视图中的国家/地区列表的代码是这样的 @Html.DropDownListFor(m => m.selectedcountry, new SelectList(Model.countries, “Value”, “Text”, Model.selectedcountry), “-Select a Country-“, new { @class = “ddlist” }) 其中一个空的下拉列表如下所示 @Html.DropDownListFor(m => m.selectedtown, new SelectList(Enumerable.Empty(), “Value”, “Text”, Model.selectedtown), […]

entity framework代码优先问题(SimpleMembership UserProfile表)

如果您使用过ASP.NET MVC 4,您会注意到Internet应用程序的默认设置是使用SimpleMembership提供程序,这一切都很好,并且工作正常。 问题来自于默认的数据库生成,他们为UserProfile定义了一个POCO,如下所示: [Table(“UserProfile”)] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } } ..然后生成如下: using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } 这工作正常,数据库生成正常,工作没有问题。 但是,如果我要像这样更改POCO并删除数据库: [Table(“UserProfile”)] public class […]

asp.net mvc父子视图,父视图更新子项

我正在使用局部视图来创建父子视图。 理想情况下,父视图上的提交按钮用于保存子值。 我有以下型号。 public class Course { public int CourseId { get; set; } public string Name { get; set; } public int Par { get; set; } public string Tee { get; set; } public decimal Rating { get; set; } public virtual IEnumerable Holes { get; set; } public static Course Create() { […]