html-helper

ASP.NET MVC HTML helper methods for new HTML5 input types

∥☆過路亽.° 提交于 2019-11-28 18:08:33
HTML5 appears to support a new range of input fields for things such as : Numbers Email addresses Colors URLs Numeric range (via a slider) Dates Search boxes Has anyone implemented HtmlHelper extension methods for ASP.NET MVC that generates these yet? It's possible to do this using an overload that accepts htmlAttributes , such as: Html.TextBoxFor(model => model.Foo, new { type="number", min="0", max="100" }) But that's not as nice (or typesafe) as: Html.NumericInputFor(model => model.Foo, min:0, max:100) Paul Hiles Just a heads up that many of these are now incorporated into MVC4 by using the

What is the difference between Html.Hidden and Html.HiddenFor

佐手、 提交于 2019-11-28 18:06:17
I can find a good definition for Html.HiddenFor on MSDN but the only thing I can find on Html.Hidden is related to problems it has. Can someone give me a good definition and an example. Kirk Woll Most of the MVC helper methods have a XXXFor variant. They are intended to be used in conjunction with a concrete model class. The idea is to allow the helper to derive the appropriate "name" attribute for the form-input control based on the property you specify in the lambda. This means that you get to eliminate "magic strings" that you would otherwise have to employ to correlate the model properties

Using helpers in rails 3 to output html

这一生的挚爱 提交于 2019-11-28 17:14:45
I'm trying my best to build a helper that outputs a <'ul> consisting of all the members of a collection. For each member of the collection I want to print out a <'li> that has a title, and a div of links to CRUD the member. This is pretty similar to what Rails outputs for scaffolding for the index view. Here is the helper I've got: def display_all(collection_sym) collection = collection_sym.to_s.capitalize.singularize.constantize.all name = collection_sym.to_s.downcase html = '' html << "<ul class=\"#{name}-list\">" for member in collection do html << content_tag(:li, :id => member.title.gsub(

Accessing attributes from Custom Html Helpers in asp.net mvc 4 razor

荒凉一梦 提交于 2019-11-28 17:07:40
问题 I have created HtmlHelper in ASP.NET MVC 4 razor view engine C#. Can I pass view model property to my helper class? For example, I have property [Required] [Display(Name = "Your Lastname")] public string Lastname { get; set; } Can I pass this property to my helper something like this @Html.Example(model => model.Lastname) and then get data annotations in helper (if this field is required what is display name and etc.)? 回答1: The [Display] attribute enriches the metadata. So you could fetch the

unable to apply Bootstrap classes to my EditorFor

不问归期 提交于 2019-11-28 14:03:06
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 ? so what are the available approaches i can follow to get this working other than upgrading my asp.net

custom htmlhelper with validation support

我与影子孤独终老i 提交于 2019-11-28 13:01:32
I'm rockin my own custom HtmlHelper to enable AutoComplete support on a Select List . This is working alright, except I need to be able to support the DataAnnotations in my ViewModel. Here's my current (working) HtmlHelper (sans validation) <Extension()> Public Function AutoCompleteDropDownList(ByVal helper As HtmlHelper, name As String, autoCompleteSelectListItem As List(Of AutoCompleteSelectListItem), htmlAttributes As Object) As MvcHtmlString Dim selectBuilder As New TagBuilder("select") selectBuilder.MergeAttribute("name", name) selectBuilder.MergeAttributes(New RouteValueDictionary

Capture wrapped content in BeginForm style disposable html helper

别说谁变了你拦得住时间么 提交于 2019-11-28 12:13:45
I am trying to write a BeginForm style html helper that uses IDisposable to wrap other code. I want the helper to only render the wrapped code if a certain condition is met (e.g. user is in a certain role). I thought that I could simply switch the context.Writer in the Begin method and switch it back in the Dispose method. The code below compiles and runs but the wrapped content gets rendered in all cases. If I step through it, the wrapped content is not written to the new StringWriter and therefore not within my control. public static IDisposable BeginSecure(this HtmlHelper html, ...) {

how to pass parameter with @url.action to controller

元气小坏坏 提交于 2019-11-28 11:56:40
i have following code snippet i want to pass data-id="0" with my @url.action , how can i do this <a class="v-patient pointer" data-id="0" href="@Url.Action("View1", "Task")">View Patient</a></td> my task controller public ActionResult View1(string id) { return View(); } If is was an ActionLink you would do this: @Html.ActionLink("View1", "Task", new {id=0}, null); So in your case, using Url.Action() it would be: href="@Url.Action("View1", "Task", new {id=0})" Which in your sample is: <a class="v-patient pointer" data-id="0" href="@Url.Action("View1", "Task", new {id=0})">View Patient</a></td>

Using ASP.NET MVC Html Helpers in a standard web forms project

隐身守侯 提交于 2019-11-28 11:31:38
问题 So for example in the code behind of a web form aspx page I would like to be able to do things like string textBoxHtml = Html.TextBox("MyTextBox"); Is this possible? Is the source code available to fork for webforms? 回答1: Possible? Yes. The entire MVC source is available at: http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&displaylang=en Good luck! You'll quickly find that pulling bits of code out of MVC is like only wanting a banana and getting

Raw ActionLink linkText

只愿长相守 提交于 2019-11-28 08:40:01
I want to put a button as the text of an @ActionLink() but I can't because it HTML-escapes my string... I found the @Html.Raw() mechanism and have tried the @ActionLink().ToHtmlString() but can't figure out how to put it together... I found an article that describes building an extension for a similar purpose but it's eeky to go to that much trouble... there must be an easy way? You could write a helper: public static class HtmlExtensions { public static IHtmlString MyActionLink( this HtmlHelper htmlHelper, string linkText, string action, string controller, object routeValues, object