c# - Need Help building Custom Html Helper for Asp.net MVC -


I was playing with some custom HTML assistants and now I am trying to create one which i jquery ajax UI Tabs.

To do this Ajax tab, you must have this format in your HTML code

  & lt; Div id = "example" & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; A href = "ahah_1.html" & gt; & Lt; Period & gt; Content 1 & lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "ahah_2.html" & gt; & Lt; Period & gt; Content 2 & lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "ahah_3.html" & gt; & Lt; Period & gt; Content 3 & lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt;  

So I can not use ActionLink because I do not think I can add any tag to the appellanlink.

So I want to make my own HTML helper, it has an action link with a span tag and possibly can later be prepared to put an undiscovered list with it.

So I'm not sure how to use ActionLink in my advantage like ActionLink has 10 overloaded methods and I would not want to redefine all of them 10 because it looks just in vain so far Can I refer to it or something like that?

I am using a method that showed my custom HTML assistants when they "HTML". For example:

  Public Static String Button (This HtmlHelper Assistant, String ID, String Value)  

So I'm not sure that I have this HtmlHelper How can i use

I do not understand this part of the line "This HtmlHelper Assistant" code.

Does it confuse me using the keyword "this" in the parameter I'm not sure what she's saying and why you need it. I do not even understand how to pass this parameter, but it does not allow its customer HTML assistants to accept "HTML" in any way.

Thanks

Excellent is just adding some code:

1) Create static classes with your assistant:

  public static class MyHtmlHelpers {public static string MySpecialActionLink (This is HtmlHelper HtmlHelper, string link text, string action name, object Route value) {var internatal tagbilder = new tagbuilder ("span") {inherhmm = (! String.isnalolactic (link text))? HttpUtility.HtmlEncode (linkText): String.Empty}; Tagbilder tagbilder = new tagbuilder ("a") {InnerHtml = innerTagBuilder.ToString (TagRenderMode.Normal); }; Var urlHelper = new UrlHelper (html.ViewContext.RequestContext); Var url = urlHelper.Action (actionName, route value); Tag Builder Merge author ("href", url); Return tagbuilder Toaster (TagRenderMode.Normal); }}  

2) Add the namespace of the MyHtmlHelpers class to Web.config:

  & lt; Page & gt; & Lt; Namespace & gt; & Lt; Add namespace = "System.Web.Mvc" /> & Lt; Add Namespace = "System.Web.Mvc.Ajax" /> & Lt; Add Namespace = "System.Web.Mvc.Html" /> & Lt; Add Namespace = "System.Web.Routing" /> & Lt; Add namespace = "System.Linq" /> & Lt; Add namespace = "System.Collections.Generic" /> & Lt; Add namespace = "MyHtmlHelpers_Namespace" /> & Lt; / Namespace & gt; & Lt; / Pages & gt;  

3) Enjoy :):

  & lt; Div id = "example" & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt;% = Html My Special ActionsLink ("Content 1", "Action 1", blank)%> & Lt; / Li & gt; & Lt; Li & gt; & Lt;% = HTML.MySpecialActionLink ("Content 2", "Action 2", new {param2 = "value2"})%> & Lt; / Li & gt; & Lt; Li & gt; & Lt;% = Html.MySpecialActionLink ("content 3", "action3", new {param3 = "value3"})%> & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt;  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -