html-helper

Migrate html helpers to ASP.NET Core

て烟熏妆下的殇ゞ 提交于 2019-12-01 04:51:44
问题 I'm converting a project to ASP.NET Core. I need to migrate lots of reusable html helpers, but html helpers do not exist in Core. Some are complex, some simple. Here's a extremely simple example: @helper EditIcon() { <i class="glyphicon glyphicon-pencil"></i> } Note that this is only an example. Point is writing a tag helper for that is gigantic overkill. Same for partials. Same for view components. We're talking about a little snippet of Razor. What is my best option? 回答1: So, seems there

Does Html.TextBox uses Request.Params instead of Model?

[亡魂溺海] 提交于 2019-12-01 04:09:05
问题 I have a simple test application: Model: public class Counter { public int Count { get; set; } public Counter() { Count = 4; } } Controller: public class TestController : Controller { public ActionResult Increment(Counter counter) { counter.Count++; return View(counter); } } View: <form action="/test/increment" method="post"> <input type="text" name="Count" value="<%= Model.Count %>" /> <input type="submit" value="Submit" /> </form> Clicking Submit I get such values: 5, 6, 7, 8, ... With Html

how does using HtmlHelper.BeginForm() work?

烂漫一生 提交于 2019-12-01 03:47:02
Ok so I want to know how <% using (Html.BeginForm()) { %> <input type="text" name="id"/> <% } %> produce <form> <input type="text" name="id"/> </form> namely how does it add the </form> at the end? I looked in codeplex and didn't find it in the htmlhelper. There is a EndForm method, but how does the above know to call it? The reason is I want to create an htmlhelper extension, but don't know how to close out on the end of a using. Any help would be appreciated :) BeginForm returns an IDisposable which calls EndForm in Dispose . When you write using(Html.BeginForm()) { ... } , the compiler

ASP.NET MVC Html.ActionLink result URL - the way of encoding

雨燕双飞 提交于 2019-12-01 03:27:29
问题 I create an amount of actions in MVC controllers. public ActionResult DoSmth1(string token) public ActionResult DoAnother2(string token) And when I have to call ActionLink.. =Html.ActionLink<SomeController>( x=> x.DoSmth(item.property), item.property) =Html.ActionLink<AnotherController>( x=> x.DoAnother(item.property), item.property) ...it generates me different URLs: /Some/DoSmth/stringvalue /Another/DoAnother?property=stringvalue Where to set the way it builds an URL? I am alr have no ideas

Setting a default selected value in DropDownList in MVC3

本小妞迷上赌 提交于 2019-12-01 03:25:26
In MVC3 I have this code at my controller. It retrieves a List of IDs\Names from Installation table and creates a ViewBag var vs = dba.Installation.OrderBy(q => q.InstName).ToList(); ViewBag.Vessels = new SelectList(vs, "InstId", "InstName"); Now, at my view. I want to render the list in a dropdown list. I used the Html helper that works fine... @Html.DropDownList("InstId",(SelectList)ViewBag.Vessels, "- Select one -") I need to set first item in the ViewBag List as a default selected value, instead of "- Select one -" text. How can I do it? Thanks in advance! There's an overload for the

Html.TextAreaFor in asp.net mvc

岁酱吖の 提交于 2019-12-01 02:36:51
I have a asp.net mvc view that allows the user to enter some description in a textarea. There are two problems that I am facing. Either when I expand the textarea it is expanding without moving other html elements or I am not able to make create a Html.TextBoxFor () multiline textbox. Can anyone suggest a solution to this? If Use Textarea how to make it expand(grow in size) so that it does not overlap with other elements or how to use Html.TextBoxFor() for multiline? This is how my code looks like <% using (Html.BeginForm()) { %> <%: Html.ValidationSummary(true)%> <fieldset> <div class="editor

Best way to render System.Drawing.Image in ASP.NET MVC 3 View

ⅰ亾dé卋堺 提交于 2019-12-01 01:43:22
问题 I have an object of type System.Drawing.Image and would like to display this image in a view. What would be the best way to do this? I have found some custom Html Helper methods that might fit the situation. Also found an example that uses a new action method that returns a FileContentResult in order to pull something like this off. I would like to know what technique is best and easiest to implement. EDIT To be more specific, I have the image in a System.Drawing.Image variable in the

Dynamically call textboxfor with reflection

巧了我就是萌 提交于 2019-12-01 00:57:53
The end result of what I am trying to do is build a form dynamically by reflecting an object and it's properties. I've created HtmlHelper methods that call TextBoxFor and CheckBoxFor and so on, but now I need help figuring out how to properly reflect the property when passing it to Html.TextBoxFor Here's the helper method: public static MvcHtmlString FormTextBox<TModel>(this HtmlHelper<TModel> helper, String id, String property_name, object model, RouteValueDictionary attributes) { Type model_type = model.GetType(); return helper.TextBoxFor(model_object => model_type.InvokeMember(property_name

Cakephp Override HtmlHelper::link

随声附和 提交于 2019-12-01 00:01:18
I want to setup HtmlHelper::link() method so the default options array have escape = false. How can I achieve this without changing the core class? OBS: I already sanitized form input, so I guess this will have no problem. Thanks in advance. Cake 2.1.5 I just implemented this and I wanted to point out a few things: Your custom html helper should extend HTML helper (and don't forget to include the HTML helper class) App::uses('HtmlHelper', 'View/Helper'); class CustomHtmlHelper extends HtmlHelper { //yadda yadda } Additionally, your call in AppController should not include the word Helper:

Setting a default selected value in DropDownList in MVC3

拟墨画扇 提交于 2019-11-30 23:39:17
问题 In MVC3 I have this code at my controller. It retrieves a List of IDs\Names from Installation table and creates a ViewBag var vs = dba.Installation.OrderBy(q => q.InstName).ToList(); ViewBag.Vessels = new SelectList(vs, "InstId", "InstName"); Now, at my view. I want to render the list in a dropdown list. I used the Html helper that works fine... @Html.DropDownList("InstId",(SelectList)ViewBag.Vessels, "- Select one -") I need to set first item in the ViewBag List as a default selected value,