Tag: 剃刀

我想让EditFor文本框只接受数字

这是我的ViewModel: [Required(ErrorMessageResourceType=typeof(Resources.ValidationsResources), ErrorMessageResourceName = “Required”)] [Range(0, 9999, ErrorMessageResourceType = typeof(Resources.ValidationsResources), ErrorMessageResourceName = “SomenteNumeros”)] public Int16 Quantidade { get; set;} 这是我的观点: Quantidade @Html.EditorFor(model => model.Quantidade) 但我想阻止这个编辑器中的所有单词,只允许数字。 我怎样才能做到这一点?

重定向到ACS并返回后,Cookie在极少数情况下为空

在我的网站上,有一个注册表。 填写完成后,用户将被重定向到Azure ACS以便登录。登录后,用户将被重定向回我的网站并进行注册和登录。 注册表由JavaScript提交。 用户填写的信息通过RegisterController中的RedirectToProvider方法保存到cookie中,用户被重定向到ACS。 当用户从ACS重定向回网站时,然后通过RegisterController中的RegisterUser方法读取cookie。 问题是:这在95%的时间都有效。 5%的时间,当用户回来时,cookie为空。 我一直无法追踪原因,我想知道是否有任何已知的问题或我可能会监督的事情。 表单代码如下所示: @using (Html.BeginForm(“RedirectToProvider”, “Register”, FormMethod.Post, new { id = “registerForm” })) … various fields… } 提交表单的RegisterRedirect()JavaScript(此处省略了相关的function): var RegisterRedirect = function () { $(“#registerForm”).valid(); $(“#registerForm”).submit(); } RegisterController中的RedirectToProvider方法: [AllowAnonymous] [HttpPost] public ActionResult RedirectToProvider(RegisterViewModel viewModel) { if (ModelState.IsValid) { var providerUrl = viewModel.SelectedProviderUrl; viewModel.SelectedProviderUrl = “”; var json = […]

我该如何调试mvc4 razor视图?

我已经习惯了C#和vb.net winforms,通常可以通过设置断点和单步执行代码来找到我需要的所有错误。 我想知道我做错了什么。 我在这里放置一个断点: public ActionResult Index(int id) { var cnty = from r in db.Clients where r.ClientID == id select r; if (cnty != null) // breakpoint here { return View(cnty); // F11 jumps over this section of code returning me to the error page below. } return HttpNotFound(); } 然而,我再也不知道它究竟出错的地方或原因。 我怎样才能找出原因或更好的错误呢? 我正在使用VS2012 mvc4 […]

ASP Net MVC – validation消息的本地化

我在asp net mvc 5应用程序中遇到了validation消息本地化的问题。 我用它进行本地化: 路线配置: [Internationalization] public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute(“DefaultLocalized”, “{language}-{culture}/{controller}/{action}/{id}”, new { controller = “Home”, action = “Index”, id = “”, language = “de”, culture = “DE” }); routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional […]

在哪里配置Razor页面语言版本到C#6?

最近我试图在我的ASP.NET MVC(5).cshtml视图中使用一些C#6新function(插值字符串),但是在运行时遇到错误消息抱怨$ 。 很明显编译器在C#5兼容模式下,或者最糟糕的是它是 C#5编译器。 在编辑器中弹出警告警告我(我不知道它是VS或ReSharper) Feature ‘Interpolated strings’ is not available in C# 5. Please use language version 6 or greater. 项目本身设置为C#6,我可以在构建时编译代码中使用C#6function,如控制器等。 问:我应该在哪里设置页面编译器版本, 当我将我的Web应用程序部署到Azure时 , 这个C#6编译器是否可用?

ASP.NET MVC3绑定到子类

我有一个类型为Question的超类,它有多个子类(例如MultipleChoiceQuestion和TextQuestion )。 每个子类都有自己的编辑器模板(例如〜/ Shared / EditorTemplates / MultipleChoiceQuestion.cshtml )。 我想要做的是创建一个Question对象列表: class Questionnaire { List Questions; } 这将真正包含子类的实例: Questions.Add(new MultipleChoiceQuestion()); Questions.Add(new TextQuestion()); 然后我将调查问卷传递给View,我打电话给: @Html.EditorFor(m => m.Questions) 视图成功呈现特定子类问题模型的正确编辑器模板。 问题是,在提交表单时,我的问卷调查模型(包含类型问题列表)仅包含问题的实例,而不包含子类的实例。 此外, Question属性的实例都为null。 作为测试,我已经传入了一个类型为MultipleChoiceQuestion的列表,它工作正常: class Questionnaire { List Questions; } 有没有办法让HttpPost Action返回我的模型,并使用我的表单数据实例化子类? 谢谢

将图表绘制到ASP.NET MVC 4(Razor,C#)网站

是否可以通过ASP.NET MVC 4(Razor)使用C#绘制图表(曲线,直方图,圆)。 我正在尝试从我的数据库中提取的数据制作一些图形。 但是,我找不到如何。 有什么建议吗? 非常感谢 !

Ajax.BeginForm导致重定向到部分视图而不是就地

我的Search.cshtml有一个名为“search-results”的div,需要更新。 SearchResults是动作名称。 我在MVC2 / VS2008项目上做了很多次,但这是我第一次使用MVC3和VS2010。 问题是,而不是我的搜索结果在我的div中呈现,它点击提交重定向我显示我的部分作为独立页面。 我已经读过这可能是因为没有启用Ajax。 我的_Layout.cshtml看起来像这样: @ViewBag.Title @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add(“telerik.common.css”).Add(“telerik.transparent.css”).Combined(true).Compress(true))) My MVC Application @(Html.Telerik().Menu() .Name(“menu”) .Items(menu => { menu.Add().Text(“Home”).Action(“Index”, “Home”); menu.Add().Text(“About”).Action(“About”, “Home”); menu.Add().Text(“Employees”).Action(“List”, “Employee”); })) @RenderBody() @(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true))) 我是否需要添加MicrosoftMvcAjax.js或jquery.unobtrusive-ajax.js? 我的web.config(root)包含以下内容: 如果我在元素的末尾添加MicrosoftMvcAjax.js,我得到一个错误,说明命名空间’Type’是来自MicrosoftMvcAjax.js第一行的未定义错误: Type.registerNamespace(‘Sys.Mvc’);Sys.Mvc.$create_AjaxOptions=function(){return {};} 我在这里想念的是什么 我确信我的代码很好,因为它几乎从我的MVC2项目中逐字复制。

使用RazorEngine同时解析Razor模板

我在MVC 3 Web应用程序中使用RazorEngine库( http://razorengine.codeplex.com/ )来使用Razor模板语言来解析字符串(不是视图)。 一般来说,这很好。 但是,当多个用户访问同时解析Razor模板的代码时,我偶尔会看到内部Razor编译器中出现的错误(请参阅下面的两个)。 我在解释这些错误时遇到了麻烦,但我的猜测是我调用Razor编译器的方式并不安全。 这是Razor编译器的已知问题吗? 正常的Razor视图( .cshtml )如何不遇到这个问题? 有没有一种解决方法比将我的所有应用程序的调用包含在互斥锁中的Razor.Parse更好? 我的调用代码如下,只是一个围绕Razor.Parse的简单包装: protected string ParseTemplate(string templateString, T model) { //This binderAssembly line is required by NUnit to prevent template compilation errors var binderAssembly = typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly; var result = Razor.Parse(templateString, model); return result; } 错误一: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative […]