I would like to create a HTML helper that works the same as Html.RenderPartial except I would like the partial to be rendered from ViewData or a model object and not a file on the filesystem.
example:
<% Html.RenderVirtualPartial("Name", Model.MyPartialContent") %>
I can return string in my helper but i need to have code tags (i...
Hi Guys
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 typ...
I am learning MVC from Stephen Walther tutorials on MSDN website. He suggests that we can create Html Helper method.
Say Example
using System;
namespace MvcApplication1.Helpers
{
public class LabelHelper
{
public static string Label(string target, string text)
{
retu...
I'm trying to write an auto-scaffolder for Index views. I'd like to be able to pass in a collection of models or view-models (e.g., IEnumerable<MyViewModel>) and get back an HTML table that uses the DisplayName attribute for the headings (th elements) and Html.Display(propertyName) for the cells (td elements). Each row should correspond ...
Hi Guys
I want to create a helper method that I can imagine has a signature similar to this:
public static MyHtmlTag GenerateTag<T>(this HtmlHelper htmlHelper, object obj)
{
// how do I create an instance of MyAnchor?
// this returns MyAnchor, which has a MyHtmlTag base
}
When I invoke the method, I want to specify a type of...
In my master page I have a top-level menu that is created using ActionLinks:
<ul id="topNav">
<li><%=Html.ActionLink("Home", "Index", "Home")%></li>
<li><%=Html.ActionLink("News", "Index", "News")%></li>
<li><%=Html.ActionLink("Projects", "Index", "Projects")%></li>
<li><%=Html.ActionLink("About", "About", "Home")%></li>
<li><...
Can somebody please suggest how I could write a Unit Test with Moq for following HtmlHelper method?
public static HtmlTagBase GenerateTag<T>(this HtmlHelper htmlHelper
, object elementData
, object attributes)
where T : HtmlTagBase
{
return (T)Activator.Creat...
Could somebody show me how you would go about creating a mock HTML Helper with Moq?
This article has a link to an article claiming to describe this, but following the link only returns an ASP.NET Runtime Error
[edit]
I asked a more specific question related to the same subject here, but it hasn't gotten any responses. I figured it was ...
I am looking to write a few helpers in my own assembly modeled after the helpers in System.web.mvc. My problem is that I cannot use the call to Tagbuilder.ToMvcHtlString since it is internal. So if I return a string it wont be ready for asp.net 4 when it comes.
I dont want to add anything to system.web.mvc as that is a given dll.
...
Hi everyone,
We're going through an ASP.Net MVC book and are having trouble with using an extenstion method within our view. The Extension method looks like this:
using System;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
namespace MvcBookApplication
{
public static class HtmlHelperExtensions
{
public static s...
Hi, How can I create a helper like the Html.Form helper, which closes the tag when you close the braces?
...
I would like to use the ajax helper to create ajax requests that send additional, dynamic data with the post (for example, get the last element with class = blogCommentDateTime and send the value of that last one to the controller which will return only blog comments after it).
I have successfully done so with the help of jQuery Form p...
Hi,
I've created a html helper that adds a css class property to a li item if the user is on the current page. The helper looks like this:
public static string MenuItem( this HtmlHelper helper, string linkText,
string actionName, string controllerName, object routeValues, object htmlAttributes )
{
string currentControllerName = ...
Hi,
I noticed some odd behaviour when using the strongly typed HtmlHelper.ActionLink() extension method from ASP.NET MVC 2 Futures. When I use it to link to a controller in an area I have to use the following attribute on this controller
[ActionLinkArea("SomeArea")]
It links properly to the actions of the controller located in SomeAr...
I want to write an HtmlHelper to render an ActionLink with pre-set values, eg.
<%=Html.PageLink("Page 1", "page-slug");%>
where PageLink is a function that calls ActionLink with a known Action and Controller, eg. "Index" and "Page".
Since HtmlHelper and UrlHelper do not exist inside a Controller or class, how do I get the relative UR...
The Html.ActionLink
<li> ${Html.ActionLink<HomeController>(c => c.Edit(ViewData.Model.Id, ViewData.Model.Title), "Edit")} </li>
When created as html shows the URL to be Edit/5006?title=One . How do I change this to a pretty URL like Edit/5006/One ?
My Edit Action method is
public ActionResult Edit(int id, string title)
...
In my view
<%= Html.DropDownListFor( x => x.Countries[ i ], Model.CountryList )%>
in my controller
public int[ ] Countries { get; set; }
public List<SelectListItem> CountryList { get; set; }
When the forms gets posted there is no problem, the dropdown is populated and the values the user selects are posted. But when I try to load ...
I want to remove if-statements from my View, but I'm having problems with predefined controls like Html.DropDownList.
For example, I have an DropDownList that in some case contains empty selection (or in other words.. possibility to Not select something) and other case is that there is no empty selection.
<% if (Model.IsCreateEmptySel...
I'm not seeing a way to create, via the HtmlHelper, a SelectListItem that will spit out the following HTML:
<option disabled="disabled">don't click this</option>
The only properties SelectListItem has are:
new SelectListItem{
Name = "don't click this",
Value = string.Empty,
Selected = false
}
The only option I see is to
Sub...
I am trying to call the RenderAction Extension Method within my own Html Helper:
System.Web.Mvc.Html.ChildActionExtensions.RenderAction(helper, "account", "login");
this is so that along with some additional logic, I would like all html helpers to use a common method name structure when calling it on the view:
<%= Html.CompanyName()....