html-helper

Parse attributes from MvcHtmlString

China☆狼群 提交于 2019-12-12 07:03:20
问题 I need to be able to parse the attributes from an MvcHtmlString (the results of an HtmlHelper extension), so that I can update and add to them. For example, take this HTML element: <input type="text" id="Name" name="Name" data-val-required="First name is required.|Please provide a first name."> I need to take the value from data-val-required , split it into two attributes with the second value going into a new attribute: <input type="text" id="Name" name="Name" data-val-required="First name

Merging attributes

北战南征 提交于 2019-12-12 05:29:02
问题 public static IHtmlString CheckBoxWithLabelFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, string labelText, object htmlAttributes) { var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData); object currentValue = metadata.Model; string property = ExpressionHelper.GetExpressionText(expression); var checkBox = new TagBuilder("input"); checkBox.AddCssClass("checkBoxWithLabel"); checkBox.GenerateId(property); checkBox

Custom Html Helper not working

与世无争的帅哥 提交于 2019-12-12 03:48:48
问题 I am trying to learn MVC3 from Pro ASP.NET MVC3 Framework. But i am stuck at one place where we add custom Html Helper. I did every thing mentioned in the book, but i am not able to add the custom Html helper. Can somebody please help. Thanks List.cshtml @model SportsStore.WebUI.Models.ProductListViewModel @{ ViewBag.Titke = "Product"; } <!DOCTYPE html> <html> <head> <title>List</title> </head> <body> <div> @foreach (var p in Model.Products) { <div class="item"> @p.Name @p.Description <h4>@p

Get comma-separated string from CheckboxList HTML Helper

。_饼干妹妹 提交于 2019-12-12 03:07:52
问题 I got the following code from the internet for CheckboxListFor html helper extension. At the moment, in the SelectedValues it is returning a List<string> of selected values from the checkboxlist. I want to get a comma-separated string in SelectedValues . Can anyone tell me how I can achieve it? Here is the code: HTMLHelper extension: /// <summary> /// Returns a checkbox for each of the provided <paramref name="items"/>. /// </summary> public static MvcHtmlString CheckBoxList(this HtmlHelper

set ActionLink routeValues dynamically

六眼飞鱼酱① 提交于 2019-12-12 02:24:24
问题 I'm working on reading a value from textBox (let it be Sam): <%= Html.TextBox("Name")%> and then on click of action link: <%: Html.ActionLink("Edit","Edit",routeValues %> I need to route (this URL should open) /Edit/Sam How can I do that? 回答1: Since you aren't using any route values above and instead just the name of the textbox you can just create a link Name your textbox "name" (if it isn't already) via the html attributes new {id="name"} (for ex) then you can just jQuery to get the value

JQuery Datepicker for multiple .NET MVC Input Fields not working

牧云@^-^@ 提交于 2019-12-11 17:34:39
问题 I have simplified my work for this question but the same problem remains. I am using the Textbox HTML helper to display empty textboxes as I loop through the items in this model. <% foreach (var item in Model) { %> <tr> <td><%: item.ID %></td> <td><%: Html.TextBox("usernames", null, new { @class = "datepicker" }) %></td> <td><%: item.Password %></td> <td> <%: item.Race %></td> </tr> <% } %> Because I have several rows this produces several fields all with the class "datepicker". I am applying

RadioButtonFor for a list of objects mvc

若如初见. 提交于 2019-12-11 16:43:33
问题 I have a Model : public class Period { public int Id { get; set; } public bool Selected { get; set; } public string DisplayText { get; set; } public string PickerFormat { get; set; } } and the ViewModel (just involved part): public class ChartsViewModel { public HistoricViewModel HistoricViewModel { get;set;} } public class HistoricViewModel { public Period SelectedPeriod { get; set; } public IEnumerable<Period> AllPeriodes { get; set; } } In my view, I want to display a list of radio buttons

Inline helpers and page output - how?

流过昼夜 提交于 2019-12-11 14:02:29
问题 I have an HtmlHelper function that returns a MvcHtmlString and which I'd like to call in an inline helper like this: @helper JsCss() { Html.Script("jquery/jquery-1.6.2", cdn: true) } I call the inline helper from my page: <head> @JsCss() </head> ...trouble is: nothing shows up on the page! it seems I have to do this: @helper JsCss() { <text> @Html.Script("jquery/jquery-1.6.2", cdn: true) </text> } so I guess the thing is I have to "print" the return value of my Html.Script call to the page...

Double input mvc extension

风格不统一 提交于 2019-12-11 13:52:19
问题 Here I was trying to make an extension with double input boxes the returned model's properties are null, They are not correctly bound or there is another issue here, please help me on writing this extension and make use of it. I need to use thousands of it during my code. public static class DoubleBoxHelper { public static MvcHtmlString DoubleBoxFor<TModel, TProperty>( this HtmlHelper<TModel> htmlHelper, //int id, Expression<Func<TModel, TProperty>> expression) { var builder = new

Image link with $confirmMessage alert in Cakephp HTMLhelper - possible?

风格不统一 提交于 2019-12-11 12:00:02
问题 Is it possible to create an image with a link that also has a pop up alert [$confirmMessage] using the html helper in CakePHP? This is my current text link: $this->Html->link('Clear list', array('controller' => 'items', 'action' => 'clearlist', $model['Model']['id']), array(), 'Clear list?') This how the image helper creates images with links: echo $this->Html->image("recipes/6.jpg", array( "alt" => "Brownies", 'url' => array('controller' => 'recipes', 'action' => 'view', 6))); However this