html-helper

Difference between HtmlTable and TagBuilder(“table”)

杀马特。学长 韩版系。学妹 提交于 2019-12-22 10:03:11
问题 Just wondering what the difference is between these two and what the benefit for one or the other of them would be when I build my table in my HtmlHelper HtmlTable table = new HtmlTable(); and: TagBuilder table = new TagBuilder("table"); This is more or less the same as this question, Why use TagBuilder instead of StringBuilder? but I'm wondering more specifically about the difference between these two . 回答1: The main difference is that HtmlTable provides typed and correctly named properties

Override EditorForModel Template

ぃ、小莉子 提交于 2019-12-22 07:23:30
问题 You can provide alternate templates for individual types, but is it possible to override the template that wraps the label, field and validation up. Change: <div class="editor-label"><label for="Content">Content</label></div> <div class="editor-field"><input class="text-box single-line" id="Content" name="Content" type="text" value="" /> </div> To: <div class="field"> <label for="Content">Content</label> <input class="text-box single-line" id="Content" name="Content" type="text" value="" /> <

How to pass in a lambda to a Razor helper method?

允我心安 提交于 2019-12-22 02:43:50
问题 I have a razor helper method that needs to take in a Func<> that will return some HTML content to print out. This is what I originally had: @helper node(string title, Func<HelperResult> descriptions) { .... <div>@descriptions()</div> .... } @node("title", new Func<HelperResult>(() => { return new HelperResult( @<text> <span>"desc1"</span> <span>"desc2"</span> </text>); })) Unfortunately with this my text never gets printed out. No error either. So I learned about inline helpers, and changed

How to pass in a lambda to a Razor helper method?

不问归期 提交于 2019-12-22 02:42:22
问题 I have a razor helper method that needs to take in a Func<> that will return some HTML content to print out. This is what I originally had: @helper node(string title, Func<HelperResult> descriptions) { .... <div>@descriptions()</div> .... } @node("title", new Func<HelperResult>(() => { return new HelperResult( @<text> <span>"desc1"</span> <span>"desc2"</span> </text>); })) Unfortunately with this my text never gets printed out. No error either. So I learned about inline helpers, and changed

Custom Attributes for SelectlistItem in MVC

一笑奈何 提交于 2019-12-21 17:20:07
问题 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. 回答1: Try this: public static MvcHtmlString CustomDropdown<TModel, TProperty>( this HtmlHelper<TModel

ASP.NET MVC Post for @Url.action()

谁都会走 提交于 2019-12-21 15:44:27
问题 I have the following controller auto-generated by asp.net // // POST: /Account/LogOff [HttpPost] [ValidateAntiForgeryToken] public ActionResult LogOff() { AuthenticationManager.SignOut(); return RedirectToAction("Index", "Home"); } Now I have a log off button. Currently it looks like this: <div class="userdrop"> <ul> <li><a href="@Url.Action("Manage", "Account")">Profile</a></li> <li><a href="@Url.Action("LogOff", "Account")">Logout</a></li> </ul> </div><!--userdrop--> But it does not work

Html.RenderPartial call from masterpage

谁都会走 提交于 2019-12-21 12:01:15
问题 Here is a scenario: Let's say I have site with two controllers responsible for displaying different type of content - Pages and Articles. I need to embed Partial View into my masterpage that will list pages and articles filtered with some criteria, and be displayed on each page. I cannot set Model on my masterpage (am I right?). How do I solve this task using Html.RenderPartial? [EDIT] Yes, I'd probably create separate partial views for listing articles and pages, but still, there is a

How to write HtmlHelper in Fluent syntax

早过忘川 提交于 2019-12-21 02:38:04
问题 I have a simple tag builder that looks like this: public static MvcHtmlString Tag(this HtmlHelper helper, string tag, string content) { var tagBuilder = new TagBuilder(tag){InnerHtml = content}; return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.NormalTag)); } And, I can use it like this: @Html.Tag("em", Model.Title) which produces: <em>The Title</em> How can this be written to use a Fluent Syntax so it's use would look like this: @Html.Tag("em").Content(Model.Title) 回答1: You have

Is this overkill, or good use of CakePHP's HTML helper?

℡╲_俬逩灬. 提交于 2019-12-20 22:02:08
问题 I just reformatted the default layout of my CakePHP application. I eliminated as much in-line html as possible by putting almost everything inside the html helper methods. It was fun, but I'm wondering what benefit I've gained from this exercise, if any? <?php $output = implode("\n", array( $html->docType(), $html->tag('html', implode("\n", array( $html->tag('head', implode("\n", array( $html->charset(), $html->tag('title', 'Title For App'), $html->css('css', NULL, array('media' => 'screen

MVC 3 Razor, Helpers with custom markup/section

荒凉一梦 提交于 2019-12-20 12:36:52
问题 I'm not even sure if this is possible, but I thought I would check to see if there is any way to make this easier. First, I have some repeated markup in my site that looks like this: <div class="module"> <h3>Title</h3> <div> <p>Information goes here</p> </div> </div> What I want to do is wrap this up in some kind of helper/section so that I could do something like this @MyHelper("This is my Title") { <p>Here is my custom markup</p> } Then, when it renders, it would inject the title passed in