Tag: asp.net mvc

如果没有将EnableOptimization设置为true,则JS包不会呈现

我不知道我做错了什么但它可能是MVC4中的一个错误。 我想知道如何解决这个问题? 工作方案 public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { ScriptBundle scriptBundle = new ScriptBundle(“~/js”); string[] scriptArray = { “~/content/plugins/jquery/jquery-1.8.2.min.js”, “~/content/plugins/jquery/jquery-ui-1.9.0.min.js”, “~/content/plugins/jquery/jquery.validate.min.js”, “~/content/plugins/jquery/jquery.validate.unobtrusive.min.js”, “~/content/plugins/bootstrap/js/bootstrap.min.js”, }; scriptBundle.Include(scriptArray); scriptBundle.IncludeDirectory(“~/content/js”, “*.js”); bundles.Add(scriptBundle); BundleTable.EnableOptimizations = true; } } @Scripts.Render(“~/js”) 转换为(例如IT WORKS!) 工作场景不是那么多 public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { ScriptBundle scriptBundle = new […]

UserControl等效于MVC3?

在Web窗体上,我们有UserControls 。 这些控件具有代码隐藏function,可以在不依赖于其他内容的不同项目/解决方案中使用。 我想创建一个控件来呈现一些控件,并且会有一些“触发事件”的链接。 我希望它们不会附加在我的网站上,我希望能够在另一个网站上使用相同的“控件”。 MVC中的等价物是什么? 是否可以使用控制器编译视图并在其他地方使用DLL?

如何使用Entity Framework执行原始SQL查询而不必使用模型?

我正在尝试学习C#ASP.NET MVC 5.我正在尝试使用Entity Framework来完成我所做的一切。 但是,我需要运行原始SQL查询并将结果返回到数组中。 这是我到目前为止所做的。 我创建了我的上下文类,它允许我连接到服务器,它还允许我在运行时更改数据库。 这是我的上下文类 using ScripterEngine.Models; using System; using System.Collections.Generic; using System.Data.Common; using System.Data.Entity; using System.Data.Entity.Core.EntityClient; using System.Data.SqlClient; using System.Linq; using System.Web; namespace ScripterEngine.DataAccessLayer { public class BaseContext : DbContext { protected string connectionName; public DbSet Campaign { get; set; } /** * Created the connection to the server using the […]

FluentValidation:检查两个字段中的一个是否为空

我有这个模型 public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } 我想创建一个validation,其中FirstName或LastName必须由用户填写。 我安装了FluentValidation并创建了一个customvalidator类 public class PersonValidator:AbstractValidator { public PersonValidator() { RuleFor((person=>person.FirstName)//don’t know how to check if one is empty } } 要检查一个字段我可以做RuleFor(person => person.FirstName).NotNull(); 但是我如何检查其中一个是否为空。 此外,一旦通过fluentValidation创建validation,是否有可能在客户端使用它来显示错误? EDIT1 protected void […]

如何在kendo ui网格中添加行号?

我的页面中有一个kendo ui网格,有一些列。 现在我想在其中添加一个列,显示行号。 我该怎么做? 谢谢。

datetime2数据类型转换为datetime数据类型Error

我有一个控制器: [HttpPost] public ActionResult Create(Auction auction) { var db = new EbuyDataContext(); db.Auctions.Add(auction); db.SaveChanges(); return View(auction); } 一个模型: public class Auction { public long Id { get; set; } public string Title { get; set; } public string Description { get; set; } public decimal StartPrice { get; set; } public decimal CurrentPrice { get; […]

如何直接在浏览器中打开pdf文件?

我想直接在浏览器中查看PDF文件。 我知道这个问题已被提出,但我找不到适用于我的解决方案。 到目前为止,这是我的动作控制器代码: public ActionResult GetPdf(string fileName) { string filePath = “~/Content/files/” + fileName; return File(filePath, “application/pdf”, fileName); } 这是我的观点: @{ doc = “Mode_d’emploi.pdf”; } @Html.ActionLink(UserResource.DocumentationLink, “GetPdf”, “General”, new { fileName = doc }, null) 当我鼠标hover时,这里的链接是链接: 我的代码的问题是pdf文件没有在浏览器中查看,但我收到一条消息,询问我是否打开或保存文件。 我知道这是可能的,我的浏览器支持它,因为我已经用另一个网站测试它,允许我直接在我的浏览器中查看pdf 。 例如,这是我鼠标hover链接(在另一个网站上)时的链接: 如您所见,生成的链接存在差异。 我不知道这是否有用。 知道如何直接在浏览器中查看我的pdf ?

如何在混合Web API和MVC应用程序中使用Autofac解析Web API控制器?

嗨,我有一个MVC应用程序,我已经为我的Web API定义了一些依赖项。 public class AutofacWebApiDependenceResolver : IDependencyResolver { private readonly IComponentContext container; public AutofacWebApiDependenceResolver(IContainer container) { if (container == null) { throw new ArgumentNullException(“container”); } this.container = container; } public object GetService(Type serviceType) { if (serviceType == null) { throw new ArgumentNullException(“serviceType”); } var ret = this.container.ResolveOptional(serviceType) ; return ret; } public IEnumerable GetServices(Type serviceType) […]

带可选参数的MVC操作 – 哪个更好?

在您的行动签名中使用以下两种备选方案是否有任何利弊: public ActionResult Action(int? x) // get MVC to bind null when no parameter is provided { if(x.HasValue) { // do something } } 要么 public ActionResult Action(int? x = null) // C# optional parameter (virtual overload) { if(x.HasValue) { // do something } }

具有过滤的dbContext的多租户Web应用程序

我是ASP.Net MVC和多租户Web应用程序的新手。 我做了很多阅读,但作为初学者,我只是按照我的理解。 所以我设法构建了一个示例场景Web应用程序,需要解决它的结尾部分。 希望这种情况对其他一些初学者也有用,但欢迎任何其他方法。 提前致谢 1)SQLServer 2008中的数据库。 2)数据层:名为MyApplication.Data的C#类库项目 public class AppUser { [Key] public virtual int AppUserID { get; set; } [Required] public virtual int TenantID { get; set; } [Required] public virtual int EmployeeID { get; set; } [Required] public virtual string Login { get; set; } [Required] public virtual string Password { […]