html-helper

Asp.Net Mvc - Html.TextBox - Set Autofocus property

穿精又带淫゛_ 提交于 2019-12-04 23:42:49
In Html 5, there is a new attribute on textbox called autofocus. The problem is that it is a boolean value (there or not there) It should look something like : <input name="a" value="" autofocus> I tried : <%= Html.TextBox( "a", null, new { autofocus } ) %> But, it gives me an error because I'm not setting a value to autofocus... I know I can do it manually, but can I do it with Html.TextBox ? Bradley Mountford Try <%= Html.TextBox( "a", null, new { autofocus = "" } ) %> According to the HTML5 spec on boolean attributes : If the attribute is present, its value must either be the empty string

HtmlHelper extension method vs partial view?

旧街凉风 提交于 2019-12-04 22:35:59
I curious when it's recommended to use HtmlHelper extension method and when to use partial view? They seem to be equally eligible in many cases. I personally think that partial view is more or less similar to usercontrol in asp.net, which act as a group of reusable functional elements. For example, if you need to make a login control box that may appear across the whole site, partial view would be better. What's more for partial view is, it is actually self-contained with its own rendering/processing strategy (and may have its own state as well) On the other hand, htmlhelper is just tools for

ASP.NET MVC3: Object from DropdownList in Null in Controller

为君一笑 提交于 2019-12-04 18:45:54
I have created a sample MVC3 application for BookShop. I have a create action. In the create action users enter name of a book, author name and select a genre name. It is working without errors. But in the controller, I am not getting the selected genre name ( - the genre object comes as null). How do we correct it? Note: When I write @Html.DropDownList("GenreId", String.Empty) the Model Binding capabilities built into ASP.NET MVC, will attempt to populate an object of that type using form inputs. E.g. it will try to set the book object’s GenreId value. But Book does not contain the property

pass data-icon attributes in razor html helper

点点圈 提交于 2019-12-04 14:28:20
I want to following html code using asp.net mvc 3 razor html helper: <input type="text" .... . placeholder="Login" data-icon="user" /> I have try this one: @Html.TextBoxFor(m => m.UserName, new { placeholder = "Login", data-icon = "user" }) or @Html.TextBoxFor(m => m.UserName, new { placeholder = "Login", @data-icon = "user" }) Displayed Error: Invalid anonymous type members declaration. This might due to dash in data-icon not taken as attributes. How could I add data-icon attributes in text box field. Yes, you can't write like that but you can write your own Extension to solve this problem.

How can I get .cshtml from Database dynamically

与世无争的帅哥 提交于 2019-12-04 10:10:18
I have to say: This is a different question from these: http://craftycodeblog.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/ ASP.NET MVC Razor: How to render a Razor Partial View's HTML inside the controller action http://blog.rocketbase.co.uk/2011/04/asp-net-mvc-virtual-path-provider/ ASP.NET MVC load Razor view from database I want to provide dynamic .cshtml Content from db when i want. Example: City Table,FreeHtml Column @model City @Html.CheckBox - @Model.Name - @Html.CustomHelper How can I write as html helper: @model City @Html.RazorRaw(Model.FreeHtml,Model) or as

Render span tag with title attribute with ASP.NET MVC 3 Helpers

为君一笑 提交于 2019-12-04 08:59:01
问题 It's possible to add a HTML title attribute to an input tag like so: @Html.TextBoxFor(model => model.Name, new { title = "Customer name" }) Is there a similar helper for static text? With @Html.DisplayFor(model => model.Name) I can render the text from a model property. How can I add HTML attributes so that I get a span tag rendered like this: <span title="Customer name">ABC</span> 回答1: Custom html helper is probably the neatest solution. public static MvcHtmlString SpanFor<TModel, TProperty>

Custom Attributes for SelectlistItem in MVC

人盡茶涼 提交于 2019-12-04 07:59:42
I would like to create a custom htmlhelper(Extension Method) for dropdownlist to accept custom attributes in the Option tag of the selectlistitem. I have a property in my model class, that I would like to include as an attribute in the option tag of the selectlist. i.e <option value ="" modelproperty =""></option> I have come across various examples but non quite specific to what I would want. Try this: public static MvcHtmlString CustomDropdown<TModel, TProperty>( this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> listOfValues,

How to do Model Binding with Jquery Ajax

你离开我真会死。 提交于 2019-12-04 07:54:23
I'd like to use model binding to keep my controllers looking cleaner, you can see how much nicer it is using model binding: public ActionResult Create(Person personToCreate) { //Create person here } vs public ActionResult Create(string firstName, string lastName, string address, string phoneNum, string email, string postalCode, string city, string province, string country) { //Create person here } When doing model binding, we can just use a form with the correct names in the Html.TextBox("") What about jquery? How can I make sure that when I do a $.post(url, data, callback, dataType) or a $

MVC HtmlHelpers trouble with Razor

给你一囗甜甜゛ 提交于 2019-12-04 07:29:39
I'm working on a non-profit donation platform and I'm using MVC for the first time. I've got the hang of it for the most part but right now I'm having a problem that I dont know how to address. I'm using the AthorizeNet.Helpers class and when I add the code from the expamples, it works for the most part except for it takes the form and puts it ABOVE the tag however it puts the form fields in the correct place. I'm trying to figure out how to render the tag in the correct place. @using AuthorizeNet.Helpers; @using (Html.BeginSIMForm("http://127.0.0.1:4768", 1.99M, "xxx_key", "yyy_key", true)) {

problems with ASP MVC + Html.DropDownList() using a ModelView Pattern

三世轮回 提交于 2019-12-04 06:25:20
问题 Recently I posted a question about the html helper dropdownlist and got it working (here). But now I have decided it was alot smarter to switch to ModelView Patterns so I have acces to strongly typed methods in my views etc. What I did was I made some adjustments to the code in my other topic in the following way: VacatureFormViewModel: public class VacaturesFormViewModel { public Vacatures Vacature { get; private set; } public SelectList EducationLevels { get; private set; } public