html-helper

Html inside label using Html helper

柔情痞子 提交于 2019-12-17 11:51:00
问题 How can I add inline html elements inside a label with Html.Label? 回答1: Looks like a good scenario for a custom helper: public static class LabelExtensions { public static MvcHtmlString LabelFor<TModel, TProperty>( this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> ex, Func<object, HelperResult> template ) { var htmlFieldName = ExpressionHelper.GetExpressionText(ex); var for = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName); var label =

Get DisplayName Attribute without using LabelFor Helper in asp.net MVC

百般思念 提交于 2019-12-17 07:08:38
问题 What is the best way to retrieve the display name attribute for an item in your model? I see a lot of people using the LabelFor helper for everything, but a label isn't appropriate if I just want to list the data out. Is there an easy way just get the Name Attribute if I just want to print it out in, say a paragraph? 回答1: <p> <%= Html.Encode( ModelMetadata.FromLambdaExpression<YourViewModel, string>( x => x.SomeProperty, ViewData).DisplayName ) %> <p> Obviously in order to avoid the spaghetti

Difference between Html.RenderAction and Html.Action

99封情书 提交于 2019-12-17 06:12:52
问题 Does anybody know what's the difference between Html.RenderAction and Html.Action? 回答1: Html.Action() – Outputs string Html.RenderAction() – Renders directly to response stream If the action returns a large amount of HTML, then rendering directly to the response stream provides better performance than outputting a string. 回答2: The difference between the two is that Html.RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount

Cakephp Override HtmlHelper::link

孤街醉人 提交于 2019-12-14 00:15:20
问题 I want to setup HtmlHelper::link() method so the default options array have escape = false. How can I achieve this without changing the core class? OBS: I already sanitized form input, so I guess this will have no problem. Thanks in advance. 回答1: Cake 2.1.5 I just implemented this and I wanted to point out a few things: Your custom html helper should extend HTML helper (and don't forget to include the HTML helper class) App::uses('HtmlHelper', 'View/Helper'); class CustomHtmlHelper extends

Single strongly Typed Partial View for two similar classes of different types

﹥>﹥吖頭↗ 提交于 2019-12-13 19:07:28
问题 I have a Register Primary View which shows two different types of Addresses 1. Home Address 2. Mailing Address public class RegisterModel { public AddressModel HomeAddress { get; set; } public AddressModel MailAddress { get; set; } } public class AddressModel { public string Street1 { get; set; } public string Street2 { get; set; } public string State { get; set; } public string City { get; set; } } My main Register View is Strongly Typed to RegisterModel as follows @model MyNamespace.Models

ActionLink to submit Model value

巧了我就是萌 提交于 2019-12-13 16:37:45
问题 I want my Ajax.ActionLink to pass a viewModel property to action. Here is my ViewModel public class ViewModel { public string Searchtext { get; set; } } My .cshtml @Ajax.ActionLink("Bottom3", "Bottom3",new { name = Model.Searchtext}, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "pointsDiv" }) using(Html.BeginForm("Bottom3", "Home", FormMethod.Get)) { @Html.TextBoxFor(x => x.Searchtext) <button type="submit">Search</button> } <div id="pointsDiv

Unit testing generic htmlHelper methods with nunit

有些话、适合烂在心里 提交于 2019-12-13 15:05:03
问题 I'm new to nUnit and I've been tasked with creating unit tests for some htmlhelper extension methods. How should I go about creating a unit test for the following method? public static MvcHtmlString EnumDropDownListForOrderBy<TModel, TEnum>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TEnum>> expression, bool orderById, string firstElement = null, object htmlAttributes = null) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); Type

Remove blank entry from EnumDropDownListFor(…)?

谁说胖子不能爱 提交于 2019-12-13 10:32:53
问题 I found a few S.O. posts regarding this problem, but none of the accepted answers worked for me. I am using an enum to create an EnumDropDownListFor and it's working, but I do not want a blank entry at the top of the drop-down. I want the user to be forced to accept one of the items from the enum . Code follows: @Html.EnumDropDownListFor(m => m.Foo, new { @class = "input-block-level " + Model.FooThingType, autocomplete = "off", style = "width: 100px;" }) Note on the above, I have tried

How to configure Checkboxes Materialize Css in Web application Asp.Net MVC

可紊 提交于 2019-12-13 08:48:43
问题 How do I configure Checkboxes in Asp.Net MVC Razor. Since in the documentation we have the following configuration Materialize for checkboxes : <p> <label> <input type = "checkbox" /> <span> Network </span> </label> </p> And in Razor I could not perform this configuration. <div class = "input-field col s12"> @Html.EditorFor (model => model.AnnualDestaque) @Html.LabelFor (model => model.AnnualDestaque) @Html.ValidationMessageFor (model => model.AnnualDestaque, "", new {@class = "text-danger"})

My html hyperlinks do not work in my OSGI bundle

与世无争的帅哥 提交于 2019-12-13 07:46:13
问题 I am using Java and HelpGUI in my OSGI bundle and the links that use do not work. When I use HelpGUI in a non-OSGI Java project, they work just fine on the same html files. Is there some security setting or something special with paths that I need to consider? Let me know, I am horribly stuck. 回答1: You should have a look at the source code of HelpGui, I can see why it doesn't quite work in OSGi (it relies on a specific URL format resources in jar files usually have). If you look at the net