html-helper

Consuming a Helper code for optgroup functionality in Asp.net MVC

隐身守侯 提交于 2019-12-18 05:57:12
问题 I don't have the experience of working with Helpers so I am bit stuck in using a code at hand. My requirement is simple and all I need is optgroup functionality in DropDownListFor extension method. While searching, I came across this Answer and have copied this as it is in a file named MyExtensionClass.cs . But, I don't know how to use this or call the extension method defined in this. Please tell me how can i use this with my list. Right now, following is the controller code for a selectlist

Is there some way to use @Html.HiddenFor for complete model?

﹥>﹥吖頭↗ 提交于 2019-12-18 05:01:19
问题 Is there a way to use (or something simular) @Html.HiddenFor for your whole model. So instead of doing something like this: @Html.HiddenFor(model => Model.Person.Name) @Html.HiddenFor(model => Model.Person.LastName) @Html.HiddenFor(model => Model.Address.Street) use something like this (this example doesn't work) @Html.HiddenFor(model => Model) I've already searched for it on stackoverflow and google...but haven't found anything about it. I need to hold on to some values for different models

MVC LINQ to SQL Table Join Record Display

一世执手 提交于 2019-12-18 03:46:08
问题 Im having problems displaying records to my view when passing viewdata to a user control. This is only apparent for linq to sql objects where I am using table joins. The exception I receive is "Unable to cast object of type '<>f__AnonymousType4 10[System.String,System.Int32,System.Nullable 1[System.DateTime],System.String,System.String,System.String,System.String,System.String,System.Nullable 1[System.Single],System.Nullable 1[System.Double]]' to type App.Models.table1." I have searched for a

unable to apply Bootstrap classes to my EditorFor

Deadly 提交于 2019-12-17 20:53:38
问题 I am working on an asp.net mvc-5 web application , and i wrote the following :- @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) & @Html.EditorFor(model => model.Name, new { @class = "form-control" }) but this will not have any effect on the generated html, but if i changed the EditorFor to be T extboxFor i will get the effect for the form-control class ? can anyone advice on this please ? i read that this is supported only inside asp.net mvc 5.1

The difference between Html.Action and Html.RenderAction

不想你离开。 提交于 2019-12-17 18:25:24
问题 I've been trying to figure out the difference between RenderAction and Action. I don't know if I'm so concerned about the differences at this point, as to why I can't get RenderAction to work. From what I can tell, I'm passing in the correct parameters. The overload I'm using seems to be the same for both: @Html.RenderAction(Action, Controller, Route) @Html.Action("Breadcrumb", "Navigation", new {SeoUrl = Model.CarlineBucket.SEOURLName}) @Html.RenderAction("Breadcrumb", "Navigation", new

There's no @Html.Button !

末鹿安然 提交于 2019-12-17 17:33:58
问题 this is weird. I see references out there for @Html.Button() but when I type that Intellisense doesn't find such a helper... there's dropdownlist, hidden, editors, et cetera, but no button! what's up with that? 回答1: public static class HtmlButtonExtension { public static MvcHtmlString Button(this HtmlHelper helper, string innerHtml, object htmlAttributes) { return Button(helper, innerHtml, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) ); } public static MvcHtmlString Button(this

Creating a SelectListItem with the disabled=“disabled” attribute

北城余情 提交于 2019-12-17 15:43:24
问题 I'm not seeing a way to create, via the HtmlHelper , a SelectListItem that will spit out the following HTML: <option disabled="disabled">don't click this</option> The only properties SelectListItem has are: new SelectListItem{ Name = "don't click this", Value = string.Empty, Selected = false } The only option I see is to Subclass the SelectListItem to add an Enabled property to get the value to the view Not use the HTML helper for DropDownList Create a new HtmlHelper extension that accepts my

How to set a default value with Html.TextBoxFor?

≯℡__Kan透↙ 提交于 2019-12-17 15:27:06
问题 Simple question, if you use the Html Helper from ASP.NET MVC Framework 1 it is easy to set a default value on a textbox because there is an overload Html.TextBox(string name, object value) . When I tried using the Html.TextBoxFor method, my first guess was to try the following which did not work: <%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %> Should I just stick with Html.TextBox(string, object) for now? 回答1: you can try this <%= Html.TextBoxFor(x => x.Age, new { @Value = "0"}) %> 回答2

Steve Sanderson's BeginCollectionItem helper won't bind correctly

99封情书 提交于 2019-12-17 12:40:08
问题 I am using Steve Sanderson's BeginCollectionItem helper and ran into a problem. I have a form that has an option to add unlimited reward fields. I am using his helper since it solved this problem with how to keep generating the fields and not have to worry about how to bind it when the form gets submitted. I have in this same form some checkboxes that there is an unknown amount. The difference with this one versus the rewards is the unknown amount will become known after a database call and

Html inside label using Html helper

僤鯓⒐⒋嵵緔 提交于 2019-12-17 11:51:49
问题 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 =