Tag: asp.net mvc 4

如何在MVC 3中将WebForms .ascx显示为局部视图

我正在构建一个新的ASP.NET MVC 3应用程序。 在这个应用程序中,我想在我的新MVC剃刀应用程序的覆盖图中显示一个旧的WebForms用户控件(.ascx / .ascx.cs)作为局部视图。 我无法在网上找到任何关于这样做的事情。 任何人都可以告诉我这是否可行,如果有的话,请指点我一些文件? 谢谢。

MVC模型没有绑定到字典

我正在使用ASP.Net MVC4(Razor)。 我有以下代码: Dictionary occasionList = new Dictionary() 关键是一个场合类别的字符串。 occassion对象有3个属性: isAttending(bool) , ID(int)和Name(string) 在我的cshtml文件中,我执行以下操作: @foreach(string s in model.occasionList .Keys) { foreach(var o in model.occasionList .Keys[s]) { @Html.CheckBoxFor(m=>m.occasionList[s].FirstOrDefault(ev=>ev.ID == o.ID).isAttending); } } 这完全绑定了加载,我在SQL中手动检查的复选框。 但是,当我将此模型POST回服务器时,occasionList字典为空。 该模型绑定正常,因为我仍然返回模型中的其他属性。 有任何想法吗? 谢谢,Dom

为什么没有重定向到ASP.NET MVC 4中查看

全部,我有一个保存已发布文件的控制器(请查看下面的代码)。 完成它需要大约20-30分钟。 但是我在保存文件后发现,RedirectToAction不起作用。 显示的IE状态栏: Waiting for http://……./index. 顺便说一下,我的会话状态存储在SQL Server中。 超时是300分钟。 我不确定这个问题是否与之前发布的IIS 7应用程序池空闲时间有关系。 虽然它没有重定向到动作,但我发现会话仍然存在。 文件和记录已成功保存。只有问题是它没有重定向。 请帮助我。谢谢。 [HttpPost] [AcceptButton(“Upload”)] public ActionResult Upload(UploadPackageModel model) { //after about 20-30 min for 160MB file-upload, runs here. DeployLogModel tempLog = null; try { if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0) { var file = Request.Files[0]; var fileName = Path.GetFileName(file.FileName); string […]

grid.mvc在Controller中使用过滤结果

我正在使用grid.mvc( http://gridmvc.codeplex.com/ )进行过滤和排序。 有人知道如何在动作控制器中处理过滤结果。 我试图通过FormCollection传递一个隐藏字段,但只传递可见值的分页原因。 或者在mvc中是否有任何良好的替代网格,您可以在其中筛选和排序并使用筛选结果和MVCController中的操作? _customersGrid.cshtml @using GridMvc.Html @using GridMvc.Site.Models @using GridMvc.Sorting @model GridMvc.Site.Models.Grids.CustomersGrid @{ ViewBag.Title = “_CustomersGrid”; } _PersonsGrid @Html.Grid(Model).Named(“customersGrid”).Columns(columns => { columns.Add(o => o.CustomerID) .Encoded(false) .Sanitized(false) .SetWidth(30) .RenderValueAs(o => Html.Hidden(“CustomerID”, o.CustomerID)); columns.Add(o => o.CompanyName) .Titled(“Name”) .SetWidth(110); columns.Add(o => o.Phone) .Titled(“Phone”) .SetWidth(250); }).WithPaging(15).Sortable().Filterable().WithMultipleFilters() Index.cshtml @{ ViewBag.Title = “Home”; } @using (Html.BeginForm(null, null, FormMethod.Post, […]

将IEnumerable 和单个模型传递给同一视图

所以我有一个名为Employee的视图,我在其中传递IEnumerable来查看以在视图中显示一组记录,如下所示: @model IEnumerable @{ var acc_status = “”; } Full Name Account Status Created by Rights Actions @foreach (var item in Model) { if (item.account_status) { acc_status = “Active”; } else { acc_status = “Inactive”; } @item.first_name @item.last_name @item.email @item.created_by @Convert.ToDateTime(item.last_login).ToString(“MM/dd/yyyy”) } 直到这一切都很好。 现在我在同一视图中有一个AddNew按钮,这将在同一个视图中切换一个modal ,其中包含所有inputs以接受细节和字段模型的某些属性。 以下是模型包含的内容: public class UserDetailViewModel { public string first_name { get; […]

ApiController可以返回带有其他对象集合的对象吗?

如果我有一个只有简单属性的Customer类(例如Name等),那么我可以创建一个派生自ApiController ,并使用URL /api/customers查询我的Customer对象。 类似地,如果我有一个具有简单属性的Order类( Description , Amount ),那么我可以创建一个OrdersController并以相同的方式访问它。 但是,如果我然后向Customer类添加一个属性,该属性列出与该Customer关联的Order : public class Customer { public int Id { get; set; } public string Name { get; set; } // … public virtual ICollection Orders { get; set; } } …然后当我尝试使用/api/customers进行查询时,我得到500服务器错误。 我可以在CustomersController放置一个断点,并且可以看到它确实调用了正确的方法,并尝试返回一个值。 但是,在框架的内容中,它无法将其转换为HTTP响应。 看起来它无法序列化Orders信息和/或打包它以获得HTTP响应,但我不确定我需要做些什么来实现这一点。 或者仅仅是WebApi的东西不是为了返回复杂的对象而设计的? 更新 :我的代码在这里: https : //gist.github.com/43ed2f29f8adfb44cef6 更新2 :有关我得到的错误的更多信息: Server error The website […]

实体类型ApplicationUser不是当前上下文Asp.Net MVC的模型的一部分

以下是我的申请所需的代码。 我在我的帐户控制器文件中收到上述错误。 我在MVC 4中使用内置的帐户注册和登录代码。 无法注册用户。 我在stackoverflow上看到下面的链接解决我的错误但无法解决它 链接我跟着 我的Web中的连接字符串。配置代码 IdentityModel.cs文件 using System.Data.Entity; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; namespace PromoteMyName.Models { // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. public class ApplicationUser : IdentityUser { public async Task GenerateUserIdentityAsync(UserManager […]

Windows 10更新后,MVC应用程序中断

今天早上我醒来时发现我服务器上的MVC 4 Web应用程序坏了。 错误消息是: An exception of type ‘System.IO.FileNotFoundException’ occurred in mscorlib.dll but was not handled in user code. Additional information: Could not load file or assembly ‘Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’ or one of its dependencies. The system cannot find the file specified. 我打开我的VS项目并从代码运行它(所以在另一台计算机上),发生了同样的错误! 我检查了我的服务器日志,发现更新是在凌晨5:06自动安装的。 其中一个更新是由安装程序包AspNetMVC4.msi完成的。 一分钟后,我的Web应用程序上的第一个错误开始流入。 在我的开发笔记本电脑上,同样的安装程序昨天(10月15日)下午1:10:10运行。 两台计算机上的问题相同。 我从未听说过Newtonsoft.Json(但现在我发现它是什么)。 看起来好像其中一个MVC dll(不太可能)或其中一个包dll(更有可能)引用了Newtonsoft。 我试图从nuget安装Newtonsoft。 这确实有一些影响,错误从FileNotFound更改为FileLoadException: An […]

如何将javascript对象传递给C#MVC 4控制器

在MVC4中,如何将javascript对象传递给AJAX中的C#控制器? 最后我尝试了这个,但它没有用。 Javascript客户端: var myData = {Propr1: ”, Propr2: ”}; $.ajax({ type: ‘POST’, data: JSON.stringify(myData), url: ‘/Home/SubmitMyData’, contentType: ‘application/json’, dataType: ‘json’, success: alert(‘Youhou’), error: alert(‘not good’) }); C#服务器端方法: public ActionResult SubmitMyData(MyParamModel myParam) { // Do my stuff here with my parameter return View(); } public class MyParamModel { string Prop1 { get; set; } string […]

自定义SimpleMembership

在阅读了关于向UserProfile表添加自定义数据的好BLOG之后,我想以UserProfile表应该存储默认数据的方式更改它+另一个存储所有其他信息的类。 使用Interenet应用程序模板创建新项目后,我创建了两个类: Student.cs [Table(“Student”)] public class Student { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public virtual int StudentId { get; set; } public virtual string Name { get; set; } public virtual string Surname { get; set; } public virtual int UserId { get; set; } } UserProfile.cs [Table(“UserProfile”)] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { […]