razor

MVC3 Razor JQuery client side validation with an additional alert box

白昼怎懂夜的黑 提交于 2020-01-15 10:15:31
问题 I am being asked to create a login form that when the user input doesn't pass validation it pops an alert box. I have everything wire up using the model based validation. ex: public class LogonViewModel { [Required( ErrorMessage = "User Name is Required")] public string UserName { get; set; } [Required( ErrorMessage = "Password is required")] public string Password { get; set; } } I have a validation summary on the page: Html.ValidationSummary() I would like the summary to be on the page just

How can I use an @HtmlHelper inside a custom @HtmlHelper?

会有一股神秘感。 提交于 2020-01-15 09:54:26
问题 I am trying to create a custom Html helper with ASP.NET MVC. I have the following code: @helper DefaultRenderer(Models.Control control) { <div class="form-group"> <label class="control-label" for="@control.Name">@control.Label</label> @Html.TextBoxFor(m => control.Value, new { @class = "form-control" }) </div> } Apparently @Html.TextBoxFor cannot be found inside a Helper .cshtml class. I can use it in a partial view which is also a .cshtml class. I can use @HtmlTextBox but then I will lose

MVC3 razor remote validation - Controller argument is always empty

非 Y 不嫁゛ 提交于 2020-01-15 09:08:08
问题 I can call the controller but the argument (string) is always null. All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address , well I can't name my controller parameter like that. So how do I get around this?

How can i make a confirm question using Ajax?

大憨熊 提交于 2020-01-15 08:51:06
问题 this is my button: @Html.ActionLink("Deletar", "Deletar", new { id = item.ID }) I tried to make a confirm question with Ajax like this @using (Ajax.BeginForm( "AjaxAction", new AjaxOptions {OnBegin ="Deletar",Confirm="Você realmente deseja isso?" })) { @Html.ActionLink("Deletar", "Deletar", new { id = item.ID },new { id = "Deletar" }) } it does not work? what can i do? 回答1: With standard link: @Html.ActionLink( "Deletar", "Deletar", new { id = item.ID }, new { onclick = "return confirm('Você

Umbraco - How can I get Publish at/Remove at date using C#

旧城冷巷雨未停 提交于 2020-01-15 03:26:09
问题 How can I get Publish at/Remove at date using C# in Umbraco? 回答1: You just need to access the ReleaseDate and ExpireDate of the Document object. var doc = new Document(nodeId); var publishAt = doc.ReleaseDate; var removeAt = doc.ExpireDate; 回答2: Your post helped me a lot. Thank you! I'm a novice on Umbraco, and I have a little comment. To get it to work we need to import the businesslogic namespace: @using umbraco.cms.businesslogic.web; It would be obvious for experienced users, but can be

How to turn a Selectlist into Html.SelectListFor()

江枫思渺然 提交于 2020-01-15 03:14:07
问题 I need the following to be turned into a @html helper for a drop down list. <select size="30" class="scrollableinside" id="CustomerSelect"> @foreach (var customer in Model.Customers) { <option value=@customer.CustomerContacts.First().CustomerContactID>@customer.CustomerName   @customer.CustomerContacts.First().Phone</option> } </select> Since I'm doing this a little unnorthodox with the .First() and the 2 pieces of data being put into the list I'm not really sure how to make a @Html

Umbraco razor template - Get Formatted Date From Field specified in parameter

こ雲淡風輕ζ 提交于 2020-01-14 19:30:49
问题 I'm trying to return a formatted date from a razor template in umbraco. I'm not sure how to get a value from a field defined in a parameter though. Here is the code I'm playing with. The field I'm passing in is called "articleDate". I'm getting the parameter value output, however when I try to get the value of the field using the parameter name it returns nothing. If I ask for the value by the field name itself, that works. How can I create a generic macro like this? @{var param = @Parameter

Can I view .html files using Razor Intellisense as if they were .cshtml files in Visual Studio 2010?

白昼怎懂夜的黑 提交于 2020-01-14 18:53:46
问题 I've gotten .Net MVC3 to process .html (and other custom extension) just like a .cshtml file but VS2010 will not highlight the Razor syntax or show Intellisense for it. How do I get VS2010 to recognize .html file as .cshtml? 回答1: It's not so easy. If you see asp.net mvc 3 source, you can see in webpages folder next things: File: RazorDebugHelpers.cs // Trim the html part of cshtml or vbhtml string outputExtension = extension.Substring(0, 3); File: RazorCodeLanguage.cs private static

Can I view .html files using Razor Intellisense as if they were .cshtml files in Visual Studio 2010?

匆匆过客 提交于 2020-01-14 18:52:11
问题 I've gotten .Net MVC3 to process .html (and other custom extension) just like a .cshtml file but VS2010 will not highlight the Razor syntax or show Intellisense for it. How do I get VS2010 to recognize .html file as .cshtml? 回答1: It's not so easy. If you see asp.net mvc 3 source, you can see in webpages folder next things: File: RazorDebugHelpers.cs // Trim the html part of cshtml or vbhtml string outputExtension = extension.Substring(0, 3); File: RazorCodeLanguage.cs private static

mvc render partial view without httpContext or controller context

ぐ巨炮叔叔 提交于 2020-01-14 10:33:13
问题 Is it possible to render partial view without ViewContext or ControllerContext? I'm trying to get PartialView Html as string from outside of Controller Action. OR Is it possible to call Controller Action from another method? (this will allow me to execute controller action and get partial view html this way). 回答1: You can try the Razor Generator Visual Studio Extension. Basically you run the custom tool on your view and it will generate a class that you can pass a model into and it will