html-helper

ASP.NET MVC: Razor @helper vs extension methods to HtmlHelper - which is preferred?

橙三吉。 提交于 2020-01-03 08:29:04
问题 The Razor view engine in ASP.NET MVC supports @helper to define little helper methods. It seems you can do much the same by adding extension methods to HtmlHelper. In what situations is it best to use each? 回答1: Subjective question, so here's my subjective and biased answer: When the helper code involves amounts of C# code use a custom HtmlHelper and when it's primary markup you could use @helper . But assuming that when you have markup you could use a partial like @Html.Partial("_foo",

ASP.NET MVC: Razor @helper vs extension methods to HtmlHelper - which is preferred?

安稳与你 提交于 2020-01-03 08:28:05
问题 The Razor view engine in ASP.NET MVC supports @helper to define little helper methods. It seems you can do much the same by adding extension methods to HtmlHelper. In what situations is it best to use each? 回答1: Subjective question, so here's my subjective and biased answer: When the helper code involves amounts of C# code use a custom HtmlHelper and when it's primary markup you could use @helper . But assuming that when you have markup you could use a partial like @Html.Partial("_foo",

Use htmlhelper to get action in BeginForm() Method of ASP.NET MVC 3

最后都变了- 提交于 2020-01-03 05:08:13
问题 In ASP.NET MVC 3 we always use using(@html.BeginForm(){ } helper (assume using without any parameters) to use forms with postback. The returned html, includes an open form tag with some attributes and action that represent the postback url. So when I overwrite my custom BeginForm helper I need this Url. This action attribute is not just action name or combination of {area}/{controller}/{action} . I think this is a same url we use to see the current page, because when we submit page we backed

Using Html.dropdownList() in Javascript Code

≡放荡痞女 提交于 2020-01-03 04:29:10
问题 I want to add row to my table dynamicly like this : var tableRef = document.getElementById('tblData').getElementsByTagName('tbody')[0]; var newRow = tableRef.insertRow(tableRef.rows.length); var newCell = newRow.insertCell(0); newCell.appendChild(document.createElement('input')); var newCell = newRow.insertCell(1); newCell.appendChild('@Html.DropDownList("AppVersionGroupId", string.Empty)'); but output is : newCell.appendChild('<select id="AppVersionGroupId" name="AppVersionGroupId"><option

MVC3 HTML helper doesn't update DropdownListFor on Submit the form

人走茶凉 提交于 2020-01-03 03:11:33
问题 I have a simple HTML form with dropdwonListFor bound to colors, a textBox below it and submit button to submit the form and save the color. When I select a color from the dropdownlist, it will change the value of the textbox below it, if the user clicks the submit form. it goes back to the controller and I save the color from the texebox and return view(model) as an action result, but the problem that the dropdownlistfor doesn't get updated with the value of the textbox whether the value in

JavaScript variable carry an ID that I need to use in a Html.ActionLink

半世苍凉 提交于 2020-01-02 06:54:30
问题 I have a JavaScript variable in my jQuery code that contains an ID that I need to use in my Html.ActionLink but it's not working: @(Html.ActionLink("Genomför", "AnswerForm", "AnswerNKI", new {id = goalcard.Id},null)) I get: 'cannot resolve symbol "goalcard"', and the reason is that goalcard is a JavaScript variable. This is what it looks like: $.post('@Url.Action("Search", "SearchNKI")', data, function (result) { $("#GoalcardSearchResult tbody").empty(); result.forEach(function(goalcard) { $(

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

痴心易碎 提交于 2020-01-02 01:08:48
问题 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 ? 回答1: Try <%= Html.TextBox( "a", null, new { autofocus = "" } ) %> According to the HTML5 spec on

pass data-icon attributes in razor html helper

若如初见. 提交于 2020-01-01 14:57:39
问题 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

Creating Image link with HTML Helper

孤人 提交于 2020-01-01 05:10:30
问题 I'm trying to create an image link with the HTML helper of Laravel 4. But it seems that isn't really working. I have this line of code {{ HTML::link("#", HTML::image("img/logo.png", "Logo") ) }} But that just outputs a strin like this: <img src="http://localhost/worker/public/img/logo" alt="Logo"> How come.?? 回答1: You probably will have to: <a href="#">{{ HTML::image("img/logo.png", "Logo") }}</a> Because, link() uses entities to escape the title: public function link($url, $title = null,

Using Generics to Create HtmlHelper Extension Methods

痞子三分冷 提交于 2019-12-31 04:50:09
问题 I'm not really familiar with creating generic methods, so I thought I'd put this question to the community & see what comes back. It might not even be a valid use of generics! I'd like to create a HtmlHelper extension method where I can specify that the method is of a certain type. I pass into the method an instance of that type, and an instance of a TagBuilder object. I then specify the class attribute of the tag to be the type of object I passed in, with all the object's properties