razor

Url.Action(action,controller,routeValues) doubling up ID in URL

我与影子孤独终老i 提交于 2019-12-24 02:09:23
问题 I am using the following code (taken from a Stackoverflow post: Action Image MVC3 Razor ) in an HTML extension helper to build an action link. My Url.Action() method is returning a url that has the routeValues both in the route as well as appended onto the url like so: /Proposals/List/Tabled?id=Tabled when what I want is just /Proposals/List?id=Tabled Any suggestions about why it wants to do this? Update : A route rule from my Global.asax file. That must be why it's doing it, but why it's

Why is my editor template ignored when I call EditorForModel?

白昼怎懂夜的黑 提交于 2019-12-24 01:25:51
问题 I have a class called LocalizedString that is defined in an external library that is referenced in my asp.net mvc 3 project. I have created an editor template called LocalizedString.cshtml in the ~\View\Shared\EditorTemplates folder. I have the following model public class Region { public LocalizedString Title { get; set; } } I have the following test page: @model Region @Html.EditorForModel() @Html.EditorFor(x => x.Title) The editor template for LocalizedString is not invoked when I call

Pass HtmlHelper instance to another method MVC3 with Razor

元气小坏坏 提交于 2019-12-24 00:53:56
问题 Ok I have created the following two methods. The first one is an extension method on HtmlHelper. The second one gets passed that instance of the helper and it makes the checkboxes. My actual example has nothing to do with checkboxes, this was just the easiest way to explain my issue. public static MvcHtmlString MakeBoxGroup(this HtmlHelper<T> Html, List<string> names) { string outStr = ""; foreach(string name in names) outStr += MakeBox(Html, name); return new MvcHtmlString(outStr); } public

Templating in ASP.Net Core

試著忘記壹切 提交于 2019-12-24 00:52:13
问题 I have a problem creating a "sub"-template in asp.net core . The idea is to define a complete html-bootstrap-block in a template file and call it in another parent/master cshtml file. ViewModel Person (filled in the controller) namespace RazorTemplating.Models.HomeViewModels { public class Person { [Required] [MinLength(2)] public string Firstname { get; set; } [Required] [MinLength(2)] public string Lastname { get; set; } [MaxLength(3)] public int Age { get; set; } public Group MainGroup {

Email format validation in mvc3 view

核能气质少年 提交于 2019-12-24 00:35:43
问题 In a View in MVC3 I want to make a jquery function which validates a textbox for an email format, but when I want to write it like this: var a = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"; It doesn't work, because MVC thinks @(...) its a Razor code. How can I do it ? 回答1: Razor allows you to enter this by typing in double @. Try @@ 回答2: @Html.Raw(" var a = "[a-z0-9....") 来源: https://stackoverflow.com

Regular Expression Date and Time

房东的猫 提交于 2019-12-24 00:35:01
问题 Hi people I have the following express validation [Required] [RegularExpression("{0:d/M/yyyy HH:mm:ss}" , ErrorMessage = "Wrong Syntax")] public string Posted { get; set; }` But it does not allow the following input which am showing as a example of date and time: 12/12/2011 00:00:00 (I do not want these exact numbers the date and time should allow any numbers which is allowed logically by date and time standards) I get the error message "Wrong Syntax" even when i input the correct code. What

C# Unable to find other properties in custom validation attribute

…衆ロ難τιáo~ 提交于 2019-12-24 00:27:18
问题 Trying to make my own Validation Attribute that uses a property name to find another property. Currently, I am having problems finding the other property. It seems I am unable to find this property (or in fact any properties). The check for property == null is always coming up as true. Any ideas why I wouldn't be able to find properties? This is the custom filter I have made protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var property =

create editable cshtml View Page in asp.net mvc 5

若如初见. 提交于 2019-12-24 00:13:04
问题 I have following cshtml view page with div sections @model IEnumerable<int> @{ ViewBag.Title = "Template"; } <!DOCTYPE html> <html> <head> <title>Create a Template</title> </head> <body> <div>Bank Brochure</div> <div>Solution by ggg.</div> </body> </html> I want to make this cshtml page div sections editable ,how can I do this 回答1: May it will helps you $('#button').on('click',function(){ $('#divvalue').html($('#editableddiv').text()); }); <script src="https://ajax.googleapis.com/ajax/libs

looking for cleaner code when embedding razor calls in text

五迷三道 提交于 2019-12-23 23:59:50
问题 I used to have something like this: We suggest you read our @Html.ActionLink("help page", "Help", "Home") before proceeding. nice and clean. then I decided we needed to internationalise the app. I couldn't figure out a better way to deal with the above than to store the following string in the resource file: We suggest you read our [HelpPage] before proceeding. and then on the view I have to do: @MvcHtmlString.Create(this.Resource("Help").ToString() .Replace("[HelpPage]", @Html.ActionLink(

ignore renderbody in razor _layout.cshtml

做~自己de王妃 提交于 2019-12-23 23:51:45
问题 I have a page for what u need to be signed in to watch it. So I want to try this code: <!DOCTYPE html> <html lang="de"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8" /> <title>@ViewBag.Title - Meine ASP.NET MVC-Anwendung</title> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <meta name="viewport" content="width=device-width" /> @Styles.Render("~/Content/css") @if (!Request.IsAuthenticated) { @Styles.Render("~/Content