html-helper

ASPNET MVC - Override Html.TextBoxFor(model.property) with a new helper with same signature?

断了今生、忘了曾经 提交于 2019-12-23 08:56:09
问题 I want to override Html.TextBoxFor() with my own helper that has the exact same signature (but a different namespace of course) - is this possible, and if so, how? The reason for this is that I have 100+ views in an already existing app, and I want to change the behaviour of TextBoxFor so that it outputs a maxLength=n attribute if the property has a [StringLength(n)] annotation. The code for automatically outputting maxlength=n is in this question: maxlength attribute of a text box from the

Remove blank/empty entry at top of EnumDropDownListFor box

老子叫甜甜 提交于 2019-12-23 07:55:27
问题 I am rendering a drop down list box using my enums and I only have 3 options, but for some reason it is displaying four. The top and default option is simply blank/empty and I want this removed. I want the top/default value to be 'Option1'. Enums: public enum EventType { [Display(Name = "Option 1")] Option1, [Display(Name = "Option 2")] Option2, [Display(Name = "Option 3")] Option3 } View: @Html.EnumDropDownListFor(model => model.EventType, null, new { @id = "eventType", @class = "form

Rails select helper setting default value

偶尔善良 提交于 2019-12-23 06:00:49
问题 Controller def edit @folder = Folder.find(params[:id]) @parents = Folder.all.where(:user_id => current_user).map{|u| [ u.name, u.id ]} end View <%= form_for(:folder, :url => {:action => 'update', :id => @folder.id}) do |f| %> <table summary="Folder form fields"> <tr> <th>Name</th> <td><%= f.text_field(:name) %></td> </tr> <tr> <th>Parent folder:</th> <td> <%= f.select(:parent_id, options_for_select(@parents) )%></td> </tr> </table>... How to set a default value in select helper with a folder

What are the html attributes for html helpers in ASP.NET MVC3 C#?

﹥>﹥吖頭↗ 提交于 2019-12-23 05:46:10
问题 when you use HtmlHelpers in MVC, you can specify a set of html attributes a a dictionary objects. I read online a lot of material about creating HtmlHelpers but I am already focusing on jQuery and other ASP.NET stuff for an application that I have to develop ASAP and I do not have time to take care of Html Helpers customization as well. I know that there are some attributes made already available by MVC3 like @class, but in the Microsoft website there is no information about the

View data dictionary overriding model data in ASP.NET MVC

让人想犯罪 __ 提交于 2019-12-23 04:24:11
问题 I have a view to create a user as follows. <% using (Html.BeginForm("SaveUser", "Security")) {%> <p> <label for="UserName">UserName:</label> <%= Html.TextBox("UserName") %> <%= Html.ValidationMessage("UserName", "*") %> </p> <p> <label for="Password">Password:</label> <%= Html.TextBox("Password") %> <%= Html.ValidationMessage("Password", "*") %> </p> <p> <input type="submit" value="Create" /> </p> <}%> When the "Create" button is clicked, the HTML form is posted to an action called "SaveUser"

Register custom control in MVC3 ASPX Partial view

混江龙づ霸主 提交于 2019-12-23 03:39:10
问题 I ask a relevant question here and as I find there is no way to use custom control in Razor views, so I get to add new ASPX partial view to use custom control, my custom control is a dll that I added to References then define Partial view as the following: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %> <%@ Register Assembly="JQControls" Namespace="JQControls" TagPrefix="PersianDatepicker" %> <PersianDatepicker:JQLoader ID="jqdb" runat="server" />

ASP.net MVC file upload to Amazon S3 with progress

那年仲夏 提交于 2019-12-23 03:13:39
问题 Good day, I have a ASP.net MVC app that needs to upload files to Amazon S3 with progress. I found a neat control called Flajaxian that does the job pretty well. The issue is that now I want to insert a row of data into a DB that keeps track of the uploads. If you look at the code below the control has a FileUploader1_ConfirmUpload event that fires after the upload has completed. Url.Action("Upload", "TracksController") does not do what I want it to, which is fire the Upload Action in the

How to create dynamic HTML table in ASP.Net MVC (analog HtmlTable in webforms)

淺唱寂寞╮ 提交于 2019-12-23 02:57:06
问题 How to create dynamic table with the complex structure and different styles of cells? I have a lot of code such as: In Controller: string styleTag = "class=\"someCssStyle\""; ViewBag.htmlRawName1 += "<td colspan=\"" + colspan + "\" " + styleTag + ">" + name + "</td>"; for (int i = 0; i < list.count; i++) { ViewBag.htmlRawName2 += "<td " + styleTag + ">" + list[i].Name + "</td>"; } In View: <table> <tr> @Html.Raw(ViewBag.htmlRawName1 ) </tr> <tr> @Html.Raw(ViewBag.htmlRawName2 ) </tr> </table>

Helper methods to generate small HTML snippets

馋奶兔 提交于 2019-12-22 17:50:37
问题 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 contained within the various models, sometimes single instances, sometimes lists of objects. At present this is done using Partial views, passing the appropriate piece of data via the model

Inheriting from HtmlHelper instead of Extending it

杀马特。学长 韩版系。学妹 提交于 2019-12-22 12:18:07
问题 I'm creating a set of helpers for rendering compatible Twitter Bootstrap html. As I see it, I have two options when it comes to how to group these methods together: Extend the HtmlHelper prefixing the methods with TB Create a new class TBootHelper which contains the methods In the second case, to get the TBoot helper available, the developer would add <pages pageBaseType="Twitter.Bootstrap.Mvc.TBootViewPage"> To it's ~/Views/web.config (as pointed by @darin) Or instantiate the helper when it