html-helper

Where to put my custom Html Helpers?

久未见 提交于 2019-12-04 06:18:48
Where to put the helper class in the project folder hierarchy ? I would suggest creating a seperate class library so that you can reuse your helpers in other projects as well. I usually just create a Common or Helpers subdirectory as a place to put these kind of things. 来源: https://stackoverflow.com/questions/1985436/where-to-put-my-custom-html-helpers

Html.RenderPartial call from masterpage

徘徊边缘 提交于 2019-12-04 03:28:10
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 barrier that I cannot and shouldn't set model on masterpage. I need somehow to say "here are the pages" as an

Cannot convert type 'System.Collections.Generic.List<string>' to 'System.Web.Mvc.SelectList'

老子叫甜甜 提交于 2019-12-03 23:21:40
I have the following Action method, which have a viewBag with a list of strings:- public ActionResult Login(string returnUrl) { List<string> domains = new List<string>(); domains.Add("DomainA"); ViewBag.ReturnUrl = returnUrl; ViewBag.Domains = domains; return View(); } and on the view i am trying to build a drop-down list that shows the viewBag strings as follow:- @Html.DropDownList("domains",(SelectList)ViewBag.domains ) But i got the following error :- Cannot convert type 'System.Collections.Generic.List' to 'System.Web.Mvc.SelectList' So can anyone adive why i can not populate my DropDown

Find Area name and Controller Name in custom Htmlhelper with ASP.NET MVC3

孤人 提交于 2019-12-03 17:26:37
问题 I try to rewrite and customize @Html.ActionLink , in one of overloads of this method the parameters are: public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName); And I want something like the above and also need to find AreaName and ControllerName without pass it by parameters, I think to use the followings: string controller = ViewContext.RouteData.Values["Controller"]; string area = ViewContext.RouteData.DataTokens["Area"]; but the error rise

Creating Image link with HTML Helper

删除回忆录丶 提交于 2019-12-03 14:08:08
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.?? 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, $attributes = array(), $secure = null) { $url = $this->url->to($url, array(), $secure); if (is_null($title) or

How to create MVC HtmlHelper table from list of objects

我的未来我决定 提交于 2019-12-03 13:34:12
问题 I am trying to create a specific HtmlHelper table extension to reduce the spaghetti code in my View. Taking a list of domain objects I would like to display a table that is a little bit more intelligent in using the properties of the domain object as columns. In addition, I would like to disable showing of some properties as columns. An idea would be to decorate properties with attributes that tell it not to be shown. Hopefully that makes sense but here's where I got to so far... public

MVC helper - using @URL for image src?

谁说我不能喝 提交于 2019-12-03 11:06:39
问题 I'm using MVC3 and have a simple helper that draws a box with some text and icons inside for a status application. A snippet: @helper Tile(string ID) { <div class="front defaulttile"> <div class="notifybar" id="NotifyBarID" > <img alt="" src="@Url.Content("~/Images/img.jpg")" style="display: inline; margin-right: 5px;" /> <p class="topstatusbartext" id="NotifyBarTextID" >Status bar text</p> </div> etc... It would be great to use @Url.Content for the image src, but I get an error it's not

Html.ActionLink with a specified HTML id?

允我心安 提交于 2019-12-03 10:29:56
问题 I'd like to give the like generated with an Html.ActionLink an HTML id so I can change the CSS depending on where I am. I have a MasterPage with a set of links and I'd like to distinguish the active "Tab" with Jquery changing the css of that active #id Right now I'm using: <%: Html.ActionLink("Some View", "Index", "controller")%> It generates: <a href="/controller">Some View</a> I'd like to generate: <a id="something" href="/controller">Some View</a> Is that possible? I've tried: <%: Html

ASP.NET MVC HtmlHelper extensions for YUI controls (Yahoo User Interfaces)?

[亡魂溺海] 提交于 2019-12-03 10:14:25
问题 Has anyone written any HTMLHelper classes for MVC that help with Yahoo's User Interface Library? For instance I have written a helper method to convert a 'menu model' into the HTML markup needed to support the Yahoo Menu Control. The MVC pattern works well here because obviously if I chose to switch to a different menu implementation I can just write a new helper and not touch the model. This code works for me but isn't fully tested and you're welcome to use it. First we need a simple data

Show “NULL” for null values in ASP.NET MVC DisplayFor Html Helper

倖福魔咒の 提交于 2019-12-03 09:42:12
Is there a way to get an @Html.DisplayFor value to show "NULL" in the view if the value of the model item is null ? Here's an example of an item in my Details view that I'm working on currently. Right now if displays nothing if the value of the Description is null . <div class="display-field"> @Html.DisplayFor(model => model.Description) </div> yes, I would recommend using the following data annotation with a nullable datetime field in your codefirst model : [Display(Name = "Last connection")] [DisplayFormat(NullDisplayText = "Never connected")] public DateTime? last_connection { get; set; }