Tag: asp.net mvc

在不使用MVC更改URL的情况下为特定URL创建路由

我有一个在www.domain.com上运行的MVC Web应用程序,我需要为另一个域www.domain2.com为同一个Web应用程序配置不同的URL绑定。 新域名www.domain2.com必须返回特定的控制器操作视图,例如/Category/Cars : routes.MapRoute( name: “www.domain2.com”, url: “www.domain2.com”, defaults: new { controller = “Category”, action = “Cars”, id = UrlParameter.Optional } ); 如何在不更改URL的情况下实现此目的,以便访问者插入urlwww.domain2.com并收到视图www.domain.com/category/cars但url仍为www.domain2.com ? 编辑: 我尝试过这种方法,但它不起作用: routes.MapRoute( “Catchdomain2”, “{www.domain2.com}”, new { controller = “Category”, action = “Cars” } );

如何在RegularExpression属性上添加多行选项?

我在用: [RegularExpression(@”^(“”|\[)?[a-zA-Z0-9′]{1,125}(“”|\])?$”)] 确保多行文本框的每一行都正确匹配。 但我无法弄清楚如何添加全局标志和多行标志选项。 MVC不可能吗? 我还有其他选择吗?

async一直向下问题

我有一个异步asp.net控制器。 该控制器调用异步方法。 实际执行异步IO工作的方法深入到我的应用程序中。 控制器和链中最后一个方法之间的一系列方法都用async修饰符标记。 以下是我如何设置代码的示例: public async Task Index(int[] ids) { List listOfDataPoints = dataPointService(ids); List dpTaskList = new List(); foreach (var x in listOfDataPoints) { dpTaskList.Add(C_Async(x)); } await Task.WhenAll(dpTaskList); return View(); } private async Task C_Async(int id) { //this method executes very fast var idTemp = paddID(id); await D_Async(idTemp); } private async Task D_Async(string […]

如何在选择文件后自动上传文件

我有以下代码用于在我的网站上传文件: @using (Html.BeginForm(“UploadProfileImage”, “Member”, FormMethod.Post, new { @encType = “multipart/form-data” })) { @Microsoft.Web.Helpers.FileUpload.GetHtml(initialNumberOfFiles: 1, includeFormTag: false, uploadText: “Upload File”,allowMoreFilesToBeAdded:false) @ViewData[“SuccessMessage”] } 我想这能够在用户从“浏览”按钮中选择文件后自动发布。 目前,每次用户选择要上传的文件时,用户都必须单击上传,无论如何要自动执行此过程?

Guid的validation

我有一个强类型视图,它有一个DropDownListFor属性。 下拉列表中的每个项目都由GUID表示。 我所追求的是一种validation用户是否从下拉列表中选择项目的方法。 目前我还没有看到使用数据注释做这件事。 无论如何使用数据注释实现这一点,因此客户端和服务器端validation将起作用。 我猜我需要制作一个自定义方法来做到这一点但是想知道是否已经存在任何东西。

DbContext处理?

的DbContext public class HaberPortalDB : DbContext { public DbSet Haberler { get; set; } public DbSet Kategoriler { get; set; } public DbSet Yazarlar { get; set; } } public class Haberler { public virtual int Id { get; set; } public virtual string Baslik { get; set; } public virtual string Aciklama { get; […]

为什么我的视图模型不能与实现接口的通用ViewModel绑定? (ASP.NET MVC 3)

我正试图通过我的View传递以下ViewModel的实例: public class CompanyListViewModel where T : ICompany { public IEnumerable CompanyList; public IEnumerable StateList; public CompanyListViewModel(IEnumerable list) { CompanyList = list; } } View采用的方式如下: @model Project.ViewModels.CompanyViewModels.CompanyListViewModel 我的控制器代码将这样的内容传递给View: CompanyListViewModel model = new CompanyListViewModel(_companyService.FilterByCompanyState(state)); ICompanyInListAsUser接口实现ICompany接口的位置。 _companyService.FilterByCompanyState(state))类返回一个IEnumerable Company对象,后者又实现了ICompanyInListAsUser接口。 出于某种原因,访问我的视图时收到以下错误: The model item passed into the dictionary is of type ‘Project.ViewModels.CompanyViewModels.CompanyListViewModel`1[Project.ViewModels.CompanyViewModels.ICompanyInListAsUser]’, but this dictionary requires a model item […]

Azure引导字体

似乎无法解决这个问题,我将自定义引导程序css和字体插入到我的azure色cdn中,但在chrome中我一直得到“来自原点的字体” http://azxxxxxx.vo.msecnd.net ‘已被阻止加载由Cross-Origin资源共享策略:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许来源“ http://localhost.domain:16300 ”。 我修改了我的bootstrap css font-face { font-family: ‘Glyphicons Halflings’; src: url(‘//azxxxxxx.vo.msecnd.net/fonts/glyphicons-halflings-regular.eot’); src: url(‘//azxxxxxx.vo.msecnd.net/fonts/glyphicons-halflings-regular.eot?#iefix’) format(’embedded-opentype’), url(‘//azxxxxxx.vo.msecnd.net/fonts/glyphicons-halflings-regular.woff’) format(‘woff’), url(‘//azxxxxxx.vo.msecnd.net/fonts/glyphicons-halflings-regular.ttf’) format(‘truetype’), url(‘//azxxxxxx.vo.msecnd.net/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular’) format(‘svg’); } 我已经阅读了一些stackoverflowpost,将以下内容添加到我的webconfig中 仍然有同样的问题,任何想法?

如何在部分类的另一半中定义的属性上使用属性?

我有一个自动生成的类来导入包含这样的(缩写)的Web服务: [System.Runtime.Serialization.DataMemberAttribute()] public System.DateTime StartDate { get { return this.StartDateField; } set { /* implementation prop changed */ } } 我想为这个成员添加一个MVC格式属性。 所以在另一个包含相同partial class定义的文件中,我想做类似以下的事情(这是非法的): [DisplayFormat(DataFormatString = “{0:dd-MM-yyyy}”, ApplyFormatInEditMode = true)] public DateTime StartDate; 部分方法在这里没有用,因为部分方法必须是私有的,具有void返回类型,必须是方法等等。 我该如何装饰这个会员?

C#MVC 4 ControllerName属性

我正在为我的MVC 4控制器提供友好的名称,我想做一些像[ActionName=”My-Friendly-Name”]样式的东西,但对于整个控制器。 我找不到关于这种属性的任何信息,那么我该如何去做呢? 另外,我需要添加一个新的MapRoute来处理它吗? 编辑: 例如,我想路由以下url: http://mysite.com/my-reports/Details/5 被路由到以下控制器: [ControllerClass=”my-reports”] // This attribute is made up. I’d like to know how to make this functionality public class ReportsController : Controller { // // GET: /Reports/ public ActionResult Index() { return View(); } public ViewResult Details(int id) { Report report = db.Reports.Single(g => g.Id == id); return […]