【c# – MVC 5模型绑定器覆盖】教程文章相关的互联网学习教程文章

c#-ASP.NET MVC 3 ViewResult子类的单元测试依赖项【代码】

我正在创建一个名为JavaScriptViewResult的非常简单的ViewResult子类,该子类在执行时调用基本实现,然后将响应的Content-Type设置为text / javascript.在尝试对该类进行单元测试时,我遇到了许多困难,难以满足ASP.NET MVC堆栈的所有依赖关系. 到目前为止,这是我使用Rhino的单元测试的外观:[TestMethod] public void TestExecuteAction() {var request = MockRepository.GenerateMock<HttpRequestBase>();request.Expect(m => m.Url)...

c#-尝试创建ASP.NET MVC 4控制器时出现FileNotFound异常【代码】

我正在尝试仅使用SQL Server 2008而不是CE遵循Contoso University tutorial.我可以使用PC的名称和Windows身份验证连接到SQL Server Management Studio中的数据库引擎.我尚未使用它创建数据库,因为我正在尝试使用EF Code First. 这是我的连接字符串:<add name="SchoolContext" connectionString="Data Source=CARSON-PC\CARSON;Integrated Security=true" providerName="System.Data.SqlClient"/>我尝试通过右键单击controllers文件...

c#-使用Asp.Net Mvc的Json.Net中的JsonRequestBehavior等效项【代码】

从ASP.NET MVC2开始,当您尝试不提供其他信息而返回Json结果时,将出现错误:This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request.现在,您必须将属性JsonRequestBehavior设置为值AllowGet:result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;我read on a post可以防止劫持. 我想知道Json.Net是否具有等效功能以防止此类攻击. 这...

c#-ASP.NET MVC 3自定义对WebGrid进行升序和降序排序【代码】

喂,我正在研究ASP.NET MVC 3应用程序. 我有一个观点var grid = new WebGrid(rowsPerPage: 10, ajaxUpdateContainerId: "GridDiv",canPage: true,canSort: true); grid.Bind(source: Model); grid.Pager(WebGridPagerModes.All); @grid.GetHtml(htmlAttributes: new { id="grid" },columns: grid.Columns(grid.Column("Name"),grid.Column("Age"),grid.Column("Sex") )在控制器中,我有一个自定义的排序算法来对数据进行排序.我既有定...

c#-MVC 3-在“视图”上创建搜索的最佳方法

我想知道在MVC 3中创建网站搜索的最佳方法是什么.我希望能够以某种方式索引我所有的静态.cshtml视图文本并使其可搜索. 我进行了一些搜索,以为IndexTank可能是要走的路,但是它似乎是最近获得的,不再受支持. 我对MVC还是很陌生,所以最简单的方法就是我在这里追求的目标.

c#-使用ASP.NET MVC上传文件3【代码】

我正在通过ASP.NET MVC 3公开一些基于REST的服务.这些服务将通过JQuery以及Windows Phone Silverligh应用程序被访问.我知道如何与典型服务进行交互.例如,我目前有类似以下的东西:[AcceptVerbs(HttpVerbs.Post)] public ActionResult AddComment(string username, string comment) {// Do stuffreturn Json(new { message = "Success" }); }我想公开一个基于REST的服务,该服务允许用户上传文件.这里的窍门是,我还需要将一些数据与每...

c#-在MVC4中使用编辑器模板提交后,未正确填充回发对象【代码】

按下“提交”按钮后找回帖子时,我遇到了MVC4和编辑器模板的麻烦.这是我的模型:public class Form {public Form(){this.Rows = new List<Row>();}public List<Row> Rows { get; set; }public int Id { get; set; } }public class Row {public Row(){this.Label = string.Empty;this.Type = string.Empty;}public string Label { get; set; }public string Type { get; set; }public int Id { get; set; } }public class SimpleRow ...

c#-MVC3应用程序中的本地化【代码】

在我的MVC 3应用程序中,我需要进行本地化.我想请教些什么是最好的方法.还有一个问题.我在应用程序中使用的是这样的模型:public class MyModel { [HiddenInput(DisplayValue = false)]public Guid? DepartmentId { get; set; }[Display(Name = "Caption")]public string Caption { get; set; }[Display(Name = "Owner")]public string Owner { get; set; }[Display(Name = "Enabled")]public bool Enabled { get; set; } ...

c#-路由到ASP.NET MVC中的根目录【代码】

我有一个ASP.NET MVC 3应用程序.我有点理解路线,但有时我会陷入困境.目前,我的文件结构如下:/ControllersChild1Controller.csChild2Controller.csRootController.cs /ViewsIndex.cshtmlTest.cshtmlChild1Index.cshtmlItem.cshtmlChild2Index.cshtmlItem.cshtml我可以从Child1和Child2中的视图中成功获取html.通过在我的浏览器中访问/ Child1 / Index或/ Child2 / Index.但是,我无法弄清楚如何仅使用/ Index来查看/ Views目录中Ind...

C#-ASP.NET MVC 4 RouteLink无法正常工作【代码】

在我的MVC 4应用程序中,我使用了Area,这是我的路线:context.MapRoute("Service_AcceptBid","Service/{controller}/{action}/{id}/{accept}",new { area = "Service", controller = "Project", action = "AcceptBid", id = UrlParameter.Optional, accept = UrlParameter.Optional });context.MapRoute("Service_BidNegotiation","Service/{controller}/{action}/{id}/{bid}",new { area = "Service", controller = "Project", act...

c#-MVC3将字典值传递到下拉列表并将关联的键绑定到模型【代码】

我正在尝试创建mvc3 c#Web应用程序.我正在尝试做的是创建一个DropDownlist并将字典传递给它. Web界面中的用户应该看到字典的值,并且该字典有效.但是我不想将所选值绑定到模型,而是希望关联的键.有可能吗? 在示例中,您将看到如何将所选值绑定到模型:@Html.DropDownListFor(model => model.EditDate, new SelectList(Versions.Values), Model.EditDate)Versions.Values是DateTimes(字典的值).在“提交”时,将选定的值绑定到model.E...

c#-(嵌入式)Raven Studio和我现有的MVC 4路由不能一起使用吗?

我是RavenDB和可嵌入东西的新手.我现在在Google上搜索了将近两个小时,但找不到解决我问题的方法;可能是因为我仍然是RavenDB n00b

C#-文件上传在ASP.NET MVC4中不起作用-移动模板【代码】

我正在将C#和ASP.NET MVC4用于Web应用程序(移动模板). 现在,我的视图中包含以下代码:@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })){ <label for="file">Upload:</label><input type="file" name="file" id="file"/><input type="submit" value="Upload" />}这在我的控制器中:[HttpPost]public ActionResult Index(HttpPostedFileBase file){string path = System.IO.Pat...

C#-ASP.NET MVC4代码优先-数据验证不起作用【代码】

我在表单中进行数据验证时遇到问题.我在模型中声明了错误消息,但似乎在View中没有任何作用.我有以下模型:public class Dog {[Key][DatabaseGenerated(DatabaseGeneratedOption.Identity)][Display(Name = "Id")]public int Id { get; set; }[Display(Name = "Name")][StringLength(20)]public string Name { get; set; }[Display(Name = "Value")][Range(1, int.MaxValue, ErrorMessage="Minimum value is 1")]public int Value {...

c#-在MVC4中的DropDownListFor()上未设置所选值【代码】

看来这个问题被问了太多次了.但是,这让我发疯. 这是我的(简化)模型.public class UserEditModel {[Required]public string Title { get; set; }private IEnumerable<SelectListItem> _titleList;public IEnumerable<SelectListItem> TitleList{get { return _titleList.Select(x => new SelectListItem {Selected = (x.Value == Title), Text = x.Text,Value = x.Value});}set { _titleList = value; }} }TitleList成员中每个Selec...