root/trunk/eCard/eCardMVC/Platnosci/Helpers/UrlImage.cs @ 882

Wersja 866, 2.1 KB (wprowadzona przez alina, 16 years temu)

re #215

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using System.Web.Routing;
7
8namespace Platnosci.Helpers
9{
10    public static class UrlImage
11    {
12        public static string Image(this HtmlHelper helper, string src, string alt)
13        {
14            TagBuilder tb = new TagBuilder("img");
15            tb.Attributes.Add("src", helper.Encode(src));
16            tb.Attributes.Add("alt", helper.Encode(alt));
17            return tb.ToString(TagRenderMode.SelfClosing);
18        }
19        public static string ImageLink(this HtmlHelper htmlHelper, string src, string alt, string querystring)
20        {
21           
22            var action = htmlHelper.CurrentAction();
23            var controller = htmlHelper.CurrentController();
24                                   
25            UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;
26            string imgtag = htmlHelper.Image(src, alt);
27           
28            RouteValueDictionary tab = new RouteValueDictionary();
29            string id = htmlHelper.ViewContext.RouteData.Values["id"].ToString();
30            tab.Add("language", alt);
31            tab.Add("id", id);
32
33            string url = urlHelper.Action(action, controller, tab);
34
35            string[] param = querystring.ToString().Split(("&").ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
36            for (int i = 0; i < param.Length; i++ )
37            {
38                if (i == 0) url += "?" + param[i];
39                else url += "&" + param[i];
40            }
41
42            TagBuilder link = new TagBuilder("a");
43            link.Attributes.Add("href", url);
44            link.InnerHtml = imgtag;
45            return link.ToString();
46        }
47        public static string CurrentController(this HtmlHelper htmlHelper)
48        {
49            return htmlHelper.ViewContext.RouteData.Values["controller"].ToString();
50        }
51
52        public static string CurrentAction(this HtmlHelper htmlHelper)
53        {
54            return htmlHelper.ViewContext.RouteData.Values["action"].ToString();
55        }       
56    }   
57}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.