Tag: asp.net mvc 4

MVC Bundling – 包含单个bundle的.min文件

我的应用程序中有一个文件,我只有一个缩小版本,我想为它创建一个包: bundles.Add(new ScriptBundle(“~/bundles/maskedinput”).Include( “~/Scripts/jquery.maskedinput-1.3.min.js”)); 问题是默认情况下在调试模式下,捆绑机制会忽略.min文件。 我不想为所有捆绑包关闭此规则,但我想为此单个捆绑包禁用它。 这可能吗?

连接两个下拉列表mvc 4

我有一个preepay产品销售。 经销商可以有经销商经销商可以为每个产品设定价格,并且每个产品都有最大限度的优惠。 现在我喜欢在销售页面中我的mvc c#site项目中有两个DropDowmList当我从第一个ddl chack产品时我想要我的其他ddl(他要销售多少产品)从我的db连接。 编辑:例如一个经销商有三个产品销售:productA – 5个单位销售productB – 20 productC – 15当他在第二个ddl或textboxForNumber(min,max)上选择productB时,他应该看到1到20的范围 我尝试创建一个这样的新模型: public int ProductObligoByDealerID { get; set; } public int DealerID { get; set; } public virtual Dealer Dealer { get; set; } public int ProductID { get; set; } public virtual Product Product { get; set; } public uint MonthObligo { […]

FileLoadException未被用户代码处理

我正在为我的MVC-4应用程序设置API,当我在Globals.asax.cs中取消注释这一行时: WebApiConfig.Register(GlobalConfiguration.Configuration); 当我重新启动项目时收到此exception: An exception of type ‘System.IO.FileLoadException’ 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 located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 我该怎么办? 更新1(截图) 据我所知,JSON.Net看起来已正确安装。 更新2 当在Globals.Asax中注释掉API路由时,JSON.Net实际上似乎有效。 […]

Web API和MVCexception处理

我们目前正在将我们的Web表单系统重新开发为Web API和MVC(这对我们来说是新技术)到目前为止,一切似乎都没问题,但我们正在努力将Web API应用程序中的错误发送回MVC应用程序。 我们意识到我们需要捕获任何exception,并将这些exception转换为HTTP响应 Web API Product控制器如下所示: public HttpResponseMessage GetProducts() { BAProduct c = new BAProduct(); var d = c.GetProducts(); if (d == null) return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, “This is a custom error message”); else return Request.CreateResponse(HttpStatusCode.OK, d); } MVC应用程序将通过以下代码调用Web API: – public T Get() using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Config.API_BaseSite); client.DefaultRequestHeaders.Accept.Add(new […]

从多个CDN位置创建脚本包

假设我们的应用程序处于脱机状态,即我们无法使用第三方CDN,因此我们正在创建自己的应用程序。 我想在一个单独的(父)Web应用程序中托管所有供应商脚本,然后将它们包含在其他几个MVC应用程序的捆绑包中。 例如 http://localhost/parentWeb/Scripts/jquery.js http://localhost/parentWeb/Scripts/jquery-ui.js http://localhost/parentWeb/Scripts/globalize.js 我想在ASP.NET MVC App网站中包含: http://localhost/parentWeb/childWeb 即做这样的事情: bundles.UseCdn = true; bundles.Add( new ScriptBundle( “~/bundles/VendorScripts”, “http://localhost/parentWeb/Scripts/jquery.js”, “http://localhost/parentWeb/Scripts/jquery-ui.js”, “http://localhost/parentWeb/Scripts/globalize.js”)); ……当然这是不可能的。 有一个很好的解决方法吗?

列表表导致“在数据库中拒绝CREATE TABLE权限”ASP.NET – MVC4

我正在使用ASP.NET MVC 4 – c#连接到实时数据库,并列出结果,但是当我去查看页面时它返回以下错误: CREATE TABLE permission denied in database ‘DatabaseName’. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: CREATE TABLE permission denied in database ‘DatabaseName’. Source Error: […]

检查用户是否在asp.net mvc Identity中扮演角色

我在使用用户和角色为数据库播种时遇到了问题。 创建了用户和角色(我可以在抛出错误后在数据库中看到它们)。 但是,当我尝试检查用户是否在角色中时,我得到一个例外。 我的代码是: public class tbInitializer : DropCreateDatabaseAlways { protected override void Seed(tbContext context) { ApplicationDbContext userscontext = new ApplicationDbContext(); var userStore = new UserStore(userscontext); var userManager = new UserManager(userStore); var roleStore = new RoleStore(userscontext); var roleManager = new RoleManager(roleStore); if(!userscontext.Users.Any(x=> x.UserName==”marktest”)) { var user = new ApplicationUser { UserName = “marktest”, Email = […]

视图标题中@model和@inherit的MVC4 Razor差异?

要@model键入视图,我们可以使用@model和@inherit 。 你能否告诉我他们两者之间的区别? 编辑: 请看这个例子 。

在Html.BeginForm MVC4控制器动作中传递多个参数

我有这样的事情: public ActionResult ImageReplace(int imgid,HttpPostedFileBase file) { string keyword = imgid.ToString(); ……. } 在我的.cshtml中: @model Models.MemberData @using (Html.BeginForm(“ImageReplace”, “Member”, FormMethod.Post, new { imgid = @Model.Id, enctype = “multipart/form-data” })) { } 这里imgid的值没有传递给控制器​​动作。 显示错误,参数字典包含参数’imgid’的非可空类型’System.Int32’的空条目,用于方法’System.Web.Mvc.ActionResult ImageReplace

属性无法防止过度发布

阻止MVC 4过度发布的最佳方法是什么? 根据MS消息来源,[Bind]属性应该是通过阻止传入的表单值进入数据库来防止过度发布的最简单方法。 使用最新版本的MVC和EF,这似乎没有像预期/广告一样工作,除非我遗漏了一些重要的东西。 从Wrox Professional ASP.NET MVC 4 (Jon Galloway的第7章)开始,以下类应该防止过度发布: [Bind(Exclude=”IsAdmin”)] public class User { public int ID { get; set; } public string FirstName { get; set; } public bool IsAdmin { get; set; } } 但是所有[Bind]属性都会阻止表单提交值绑定到模型。 然后,模型具有空白/默认值,并将其写回数据库。 在这种情况下,它会确保IsAdmin = false每次使用此模型调用.SaveChanges()。 任何“真实”值都会被覆盖。 这是一个巨大的安全失败。 替代语法 – 将[Bind]放在Edit controller action参数中 – 完全相同: public ActionResult Edit([Bind(Exclude […]