html-helper

@Html.DisplayNameFor for details model

萝らか妹 提交于 2019-11-29 10:57:59
问题 In my model I have an Entity public class Carrier { public Guid CarrierId { get; set; } public string Name { get; set; } } I also have a ViewModel public class CarrierIndexViewModel { public IEnumerable<Carrier> Carriers { get; set; } public PagingInfo PagingInfo { get; set; } } I have a strongly-typed (CarrierIndexViewModel) Index View, which is suppose to display a table of Carrier using PagingInfo. I'm trying to use Html helper to display Carrier.Name in my table's header When I used

Html.TextBox conditional attribute with ASP.NET MVC Preview 5

让人想犯罪 __ 提交于 2019-11-29 10:44:38
问题 I have a strongly-typed MVC View Control which is responsible for the UI where users can create and edit Client items. I'd like them to be able to define the ClientId on creation, but not edit, and this to be reflected in the UI. To this end, I have the following line: <%= Html.TextBox("Client.ClientId", ViewData.Model.ClientId, new { @readonly = (ViewData.Model.ClientId != null && ViewData.Model.ClientId.Length > 0 ? "readonly" : "false") } ) %> It seems that no matter what value I give the

Radio Button generates duplicate HTML id-s

故事扮演 提交于 2019-11-29 10:40:23
问题 It seems that the default ASP.NET MVC2 Html helper generates duplicate HTML IDs when using code like this (EditorTemplates/UserType.ascx): <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<UserType>" %> <%: Html.RadioButton("", UserType.Primary, Model == UserType.Primary) %> <%: Html.RadioButton("", UserType.Standard, Model == UserType.Standard) %> <%: Html.RadioButton("", UserType.ReadOnly, Model == UserType.ReadOnly) %> The HTML it produces is: <input checked="checked" id=

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

不羁的心 提交于 2019-11-29 10:31:03
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 for which i want to use the extension methods. ViewBag.ParentCategoryId = new SelectList(db.Categories

How to use MVC Html Helper .DropDownListFor<> with an Enum

百般思念 提交于 2019-11-29 09:54:46
问题 In my MVC 3 Razor app, I have a Model with an enum.. Model Example: public class EmployeeModel { public enum Title { Accountant = 111, Sales = 222, Production = 333 } [Required] public string Name {get; set;} [Required] public Title JobTitle {get; set;} } In my View I would like to use the Html helpers to build an Html Form... View Example: @model ..Models.EmployeeModel @using (Html.BeginForm()) { @Html.LabelFor(m => m.Name) @Html.TextBoxFor(m => m.Name) <br> @Html.LabelFor(m => m.JobTitle)

MVC3: How to get currently executing view or partial view programatically inside a HtmlHelper extension?

我是研究僧i 提交于 2019-11-29 06:56:51
How to get currently executing view name or partial view name programmatically inside a HtmlHelper extension? In my situation, I can't use ViewData or can't pass view name to the extension from the View. verfailliep var webPage = htmlhelper.ViewDataContainer as WebPageBase; var virtualPath = webPage.VirtualPath; Leniel Maccaferri This is your best bet: Retrieve the current view name in ASP.NET MVC? There is one dirty way to find real path even for partial view but it is really.. dirty. helper.ViewDataContainer is of type like "ASP._Page_Areas_Users_Views_Customers_PersonContactsModel_cshtml".

Pass SelectedValue of DropDownList in Html.BeginForm() in ASP.NEt MVC 3

吃可爱长大的小学妹 提交于 2019-11-29 05:19:58
This is my View Code: @using(Html.BeginForm(new { SelectedId = /*SelectedValue of DropDown*/ })) { <fieldset> <dl> <dt> @Html.Label(Model.Category) </dt> <dd> @Html.DropDownListFor(model => Model.Category, CategoryList) </dd> </dl> </fieldset> <input type="submit" value="Search" /> } As code shown I need to pass the dropdown selected value to the action in BeginForm() Html helper. What is your suggestion? Darin Dimitrov The selected value will be passed when the form is submitted because the dropdown list is represented by a <select> element. You just need to adapt your view model so that it

Is it possible to create a custom ASP.NET MVC strongly typed HTML Helper?

大城市里の小女人 提交于 2019-11-29 03:21:02
I was wondering if it is possible to create a custom strongly typed HTML Helper in ASP.NET MVC 2? Creating a regular (read not-strongly-typed) helper is straightforward but i am having difficulty creating strongly typed versions. For example, I would like to create a DatePickerFor html helper... Any guidance or snippets would be greatly appreciated, Thank you in advance! JP Ok, I figured it out (and it was pretty straightforward...). Posting one of my overloads in case anyone else runs into this question. public static string DatePickerFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper

MVC LINQ to SQL Table Join Record Display

試著忘記壹切 提交于 2019-11-29 02:45:26
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 fix to this issue but not too familiar on whats wrong here for me to search for the right subject.

Surrounding a ValidationSummary with a box via CSS

丶灬走出姿态 提交于 2019-11-29 02:17:30
By default Html.ValidationSummary() produces HTML like this: <span class="validation-summary-errors">There were some errors...</span> <ul class="validation-summary-errors"> <li>First Name too long</li> <li>Invalid Email Address</li> </ul> I'd like to select the entire validation summary and add a bounding box around it via CSS, so I am adding a CSS class like this: .validation-summary-errors{ background-color:#D9FFB2; border: 1px solid #5CBA30; color:#000000; margin-top:15px; margin-bottom:15px; } Now the problem is that this draws separate boxes around the validation summary message and each