FAQ Database Discussion Community


HTML.TextBoxFor is set readonly before value set

model-view-controller,model,html-helper,readonly,html.textboxfor
I have the following HTML helper textbox: @Html.TextBoxFor(m => m.Email, Model.Active ? new { @readonly = "readonly", @style = "background:#E8E8E8" } : new Object { }) When I change the email value in the action (in the model being returned) then set the active=true (which is also in the model)...

How to update multiple dropdownlists using Ajax in Asp.net-MVC

jquery,ajax,asp.net-mvc,html-helper,html.dropdownlistfor
I have multiple identical dropdownlists created by a @html helper. In each dropdown, there is one option which is named "Create a new one". When I click this option, there is popup showing up and allows me to fill out infor and create a new option. I'm totally up to...

Html.BeginForm() not passing the model

c#,asp.net-mvc,razor,html-helper,html.beginform
I have the following cshtml form: model Scraper.Facade.PlayerRow @using (Html.BeginForm("Calculate", "Home", FormMethod.Post)) { <table class="table table-striped table-bordered table-condensed table-responsive table-hover"> @foreach (var player in Model.AttribsPlayerLine) { <thead> <tr class="success"> @foreach (var attrib in player.AttribsPlayerList) { [email protected](x => Model.tytul) <th data-field="@attrib.attribName">@Html.DisplayFor(x => attrib.attribName) </th> } </tr> <tr...

How can I convert anonymous object HTML attributes to a Dictionary

asp.net-mvc,html-helper
I'm providing an extra overload to RadioButtonFor and want to add a Key Value pair to the HTML Attributes that are passed in. As an example I am passing in something like: new { id = "someID" } When i the use the HtmlHelper.AnonymousObjectToHtmlAttributes method as seems to be the...

Intellisense for model properties not working in View for HtmlHelper

c#,asp.net-mvc,visual-studio-2013,html-helper
My question is simple and might not be important to other coders, but it would really help a lot if some one can explain to me why I can't get the Intellisense working When using DisplayNameFor. It is working on DisplayFor or other models, but not this one. While it...

How to add an Option label on ListBoxFor HTML Helper in ASP.Net MVC

asp.net-mvc,asp.net-mvc-4,html-helper
How can I add an option label like the one existent on the DropDownListFor for a ListBoxFor HTML Helper ? I have the code similar to bellow: <%= Html.ListBoxFor( m => m.SelectedElements, new MultiSelectList(Model.AllPossibleElements, "ID", "Text")) %> And the image bellow is the output: I would like to have a...

How to add ng-click to @Html.TextBoxFor in MVC Razor

asp.net-mvc,angularjs,razor,html-helper
How can I give my TextBox, ng-click attribute when using Html.TextBoxFor? @Html.TextBoxFor(model => model.User.Firstname, new { @class = "form-control required", placeholder = "نام" }) ...

Custom HTML Helpers, What is: this HtmlHelper html

asp.net-mvc,html-helper
I have two questions about creating custom HTML Helpers. 1) Where would my method be placed so that it can be used with @Html? I've figured out how use it with something like @MyCustomClass. Either will work, I suppose. Just curious. 2) More importantly, what is "this HtmlHelper htmlHelper"? I...

Html.ActionLink extension

c#,asp.net-mvc,razor,html-helper,tagbuilder
I am trying to extend the Html.ActionLink as I want to add a custom meta data for a shared component (in this case a modal). My aim is to further extend the LinkExtensions class within .Net MVC which will add a value to the html class attribute and add a...

How to use @Html.DisplayFor in ForEach statement

c#,asp.net-mvc,razor,html-helper
I am trying to use @HTML.DisplayFor in @ForEach statement but not successful. The following is my existing code: @foreach (var cost in Model.CustomerCost) { <tr> <td>@cost .CustomerName</td> <td>@(cost.Cost!= 0 ? string.Format("{0:C}", cost.Cost) + " USD" : "-")</td> </tr> } However, i am trying to replace the following line of code...

Create CheckboxFor MVC helper with title attribute from model description

asp.net-mvc,html-helper
I've created a text box helper to add a title (tooltip) taken from the description attribute for the field in a model: public static MvcHtmlString TextBoxForWithTitle<Tmodel, TProperty>(this HtmlHelper<Tmodel> htmlHelper, Expression<Func<Tmodel, TProperty>> expression, object htmlAttributes = null) { var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); string htmlFieldName = ExpressionHelper.GetExpressionText(expression); string textboxText = metaData.DisplayName...

which HTML helper bypasses all templates and renders a simple string?

asp.net-mvc,html-helper
this question I got from some tests: Which of the following templated HTML helpers of MVC bypasses all templates and renders a simple string representation of the specified model property? and options: Display Label DisplayText Editor as I understand, it means, that which helper displays property as string? The correct...

I can't adjust the width of my html.EditorFor box within the helper method

html,css,razor,asp.net-mvc-5,html-helper
VS2013, MVC5, Razor, VB I'm not yet that fluent with CSS files, so maybe this is my chance to learn, but I also thought that I should be able to add something to the html.EditorFor command to make the displayed box wider. This is my original code from the scaffold:...

Is it possible to append html to a class or div using razor syntax

razor,html-helper,asp.net-mvc-views
I am coding a MVC 5 internet application and have a question in regards to accesssing html classes or divs via razor syntax. Is it possible to access a html class or div via razor syntax and append some html code to the class or div? Is there a html...

Executing a controller action when a button is clicked on the client

c#,ajax,asp.net-mvc,razor,html-helper
Are we supposed to be able to follow a AJAX call in the debugger to see what's going on? Because for some reason it seems like the call isn't going to where it's supposed to go to. When stepping through the program, after the url: [email protected]("DidItWork", "Home") call, it goes...

MVC TextBox with name specified not binding model on post

c#,asp.net-mvc,html-helper
This is like MVC 101 here so I feel completely helpless on why this isn't working. I have an extremely basic Model: public class StockEnrollmentModel { [Required] [DisplayName("Employee Name:")] public string EmployeeName { get; set; } } My view looks like this: @using (Html.BeginForm("SimulateForm", "HR", FormMethod.Post)) { <div class="row"> <div...

Single using statement, multiple MVC views

c#,asp.net,asp.net-mvc,namespaces,html-helper
I've written a few extension methods (HTML helpers) and would like to use them throughout multiple views, this... @using My.Extensions.Namespace @Html.MyExtension() ...obviously works. But it means including the using statement in every single view (there'll be many). If this is the only approach, that's fine, but I'm interested if there's...

I can't call Widget for a new Admin Plugin in NopCommerce

c#,.net,html-helper,nopcommerce
I Create a New plugin to manage back Office menus, I implement the interface IWidgetPlugin to create a new widget zone : public IList<string> GetWidgetZones() { return new List<string>(){ "ebm_MenuManager_BackOffice" }; } And I had called this widget zone from one view "_AdminLayout.csHtml" under Nop.Admin project with the extended helper...

How to use Url.Action in Razor view in App_Code folder

asp.net-mvc,asp.net-mvc-4,razor,html-helper,razor-2
How to use Url.Action() in Razor helper from App_Code folder ? I tried according to Why I cant use Html.RenderPartial in razor helper view File in App_Code Folder? @using System.Web.Mvc.Html @helper Tabel(System.Web.Mvc.HtmlHelper html) { @Html.Raw(Url.Action("Index", "Home")) } but got compile error CS0103: The name 'Url' does not exist in the...

Action Method Not Found — Even Though It IS In The Controller

c#,asp.net-mvc,twitter-bootstrap,razor,html-helper
My assumption after reading through the documentation was that we could use @Html.Action("ActionName", "ControllerName") to call an action method in a controller from a view. Is that a false assumption? Because if my logic/assumption is wrong to begin with it would be helpful to know. I have the following code...

Trying to get data shown in a drop down list

c#,asp.net-mvc,razor,html-helper
I have tried a lot of different solutions online, but I haven't been able to find any solutions which implement the solution I am looking for correctly. I want to combine two attributes of a table, these being FirstName and LastName, and then I want to display these coupled attributes...

HtmlHelper with two generic parameters?

c#,generics,html-helper
Okay, so I currently have an HTMLHelper like-so: public static MvcHtmlString BackLink<TVM>(this HtmlHelper<TVM> helper, ...) where TVM : VM // Usage: @Html.BackLink(...) Is there a way to do this, while maintaining the usage from above? public static MvcHtmlString BackLink<TVM, TM>(this HtmlHelper<TVM> helper, ...) where TVM : VM<TM> // Where VM<TM>...

MVC HTML Helpers: Get all validation attributes

c#,asp.net-mvc,validation,html-helper
When it comes to making custom helpers, how can we get the value for the validation attributes (client-side validation)? for example the built in helpers do something like this: <label class="control-label " for="Starts">Starts</label> <span class="field-validation-valid text-danger" data-valmsg-for="Starts" data-valmsg-replace="true"></span> <input class="form-control text-box single-line" data-val="true" data-val-date="The field Starts must be a date."...

Html.ActionLink text styling

html,asp.net-mvc,html-helper,html.actionlink
I want to style only part of text inside my ActionLink, I need the plus sign to be bold. In pure html I can do it this way. <a class="topMenu" href="#"><span style="font-weight:bold;">+</span>Invite User</a> If try it with ActionLink like this: @Html.ActionLink("<span style="font-weight:bold;">+</span>Invite User", "Invite", "Account", new { @class = "topMenu"...

CheckBoxList for many-to-many relationship in ASP.NET MVC

c#,asp.net-mvc,razor,html-helper,checkboxlist
I am trying to implement a check box list in MVC for a many-to-many relationship (Article - Category). I have tried this, but I does not work. Does anybody know a different and properly approach to get it. In the domain model: public class Article { public int Id {...

DropDownListFor selected value not working

html,asp.net-mvc,razor,html-helper,html.dropdownlistfor
So I have this in my view(I have broken it out into a foreach so I could debug it properly). And according to the objects that are created it looks good. I get 1 item that has the selected true. @{ var useritems = new List<SelectListItem>(); foreach (var si in...

Xamarin Studio HtmlHelper Missing

asp.net-mvc-4,razor,xamarin,html-helper,xamarin-studio
For some reason my HtmlHelper won't load in my Razor view. If you type @Html. , a popup box should pop up with a bunch of Html controls. I.E. ActionLink But It does not. Does anyone know why? Main Web.conf <assemblies> <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <add assembly="System.Core, Version=4.0.0.0,...

What is the preferred way to standardise complex html views for data types?

asp.net-mvc,html-helper,mvc-editor-templates
I have code like this that I repeat through many MVC editing views. This example is the default way we display a checkbox, but similar repetition is found with other input types. <div class="form-group"> @Html.LabelFor(model => model.IsLive, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-8 checkbox"> <div class="col-xs-1">...

How to pass Area in Url.Action?

asp.net-mvc,html-helper,html.actionlink,url.action
The problem in Html.ActionLink() is that you can't add additional html content inside the tag that it generates. For example, if you want to add an icon besides the text like: <a href="/Admin/Users"><i class="fa fa-users"></i> Go to Users</a> Using Html.ActionLink(), you can only generate: <a href="/Admin/Users">Go to Users</a> So, to...

How to create click event for navigation drop down using html helper class?

javascript,jquery,html,html-helper
I am using MVC 5. I have created navigation drop down. This is my code: <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="menu"> Report <b class="caret"></b> </a> <ul class="dropdown-menu"> <li class="myselector"><a href="#">a </a></li> <li><a href="#">b </a></li> </ul> </li> Now I have same controller but different actions for a and for b....

ASP.Net MVC TextBoxFor ignore my format

c#,asp.net-mvc,html-helper,fluentvalidation
I create some helper method and create TextBoxFor inside it. input.AppendLine(html.TextBoxFor(expression, format, attributes).ToString()); My format was "{0:dd/MM/yyyy}". It's work totally fine and render as <input class="form-control req" data-val="true" data-val-date="The field detr must be a date." id="detr" name="detr" type="text" value="25/05/2558" /> But when ModelState has error on this field, TextBoxFor was...

Helper methods to generate small HTML snippets

c#,asp.net-mvc,asp.net-mvc-4,html-helper
I'm using ASP.NET MVC to separate my HTML views from my Models. However there's a specific situation that is confusing me slightly. I have several commonly used small panels of information, which themselves are comprised of a number of smaller panels of information. these get their data from a subclass...

Radio Button For Enum (DataAnnotation)

c#,enums,radio-button,data-annotations,html-helper
I have this enum: [Display(Name = "Primary incomplete")] PrimaryIncomplete = 1, [Display(Name = "Primary")] Primary = 2, [Display(Name = "Secondary incomplete")] SecondaryIncomplete = 3, [Display(Name = "Secondary")] Secondary = 4, [Display(Name = "Higher education incomplete")] HigherEducationIncomplete = 5, [Display(Name = "Higher education")] HigherEducation = 6, [Display(Name = "Post-Graduation/MBA")] PostGraduationMBA =...

How to display name of MVC model?

asp.net-mvc,model-view-controller,html-helper
I have a class like this: Public Class AuthKey <StringLength(45, ErrorMessage:="Name must not less then 5 characters and not exceed 45 characters.", MinimumLength:=5)> <Display(Name:="Name", Description:="Authentication name.")> _ Public Property name As String End Class I'd like to view the property display name and description, not the property value. I try...

How to get Display Text from EnumDropDownListFor on post?

c#,asp.net-mvc,enums,html-helper
Is there a way to get DisplayName (Text) from EnumDropDownListFor helper for enum? Enum: public enum PartnersGroup { [Display(Name="Partner_SystemsGroup",ResourceType=typeof(Global) )] SystemsGroup, [Display(Name="Partner_SoftwarePartners",ResourceType=typeof(Global))] SoftwarePartners, [Display(Name="Partner_IntegrationPartners",ResourceType=typeof(Global))] IntegrationPartners, } Model public class Partner { public PartnersGroup PartnersGroup { get; set; } } Controller // GET: Partners/Create public ActionResult Create() { ---- return...

EnumDropDownListFor using Reflection throwing “Return type 'System.Object' is not supported.”

c#,asp.net,asp.net-mvc,razor,html-helper
I'm trying to build out a settings page using reflection. Some options are enums, but the standard @Html.EditorFor() gives a text box rather than a dropdown on these properties. I have an approach sort-of working using @Html.DropDownList(), but I want the "for" helper to get the benefits of having the...

using keyword inside foreach ASP MVC

asp.net,asp.net-mvc,razor,model-view-controller,html-helper
Inside my view i need to use a form on every iteration, but if I put @using inside foreach it isn't working, @foreach (var item in list) { <tr> <td>@Html.DisplayName(item.name)</td> @using(Html.BeginForm("Index", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) { <td>@Html.TextBoxFor(model=>...