与@ Ajax.ActionLink动态图像和格式化参数 [英] Dynamic images and formatting parameters with @Ajax.ActionLink

查看:124
本文介绍了与@ Ajax.ActionLink动态图像和格式化参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更改以下工作code到阿贾克斯。

 < A HREF =@ Url.Action(指数,新{PN = PC})>
   < IMG SRC =@ Url.Content(〜/图片/+ @photoFile [PC]),ID =imgnbWIDTH =100px的高度=150像素ALT =照片/>&LT ; / a取代; < BR />
 

在code需要处理字符串[]变量,@photoFile [PC]),并采取格式化(ID =imgnbWIDTH =100px的高度=150像素ALT =照片) 。 (imgnb是CSS,没有图像边框)

梭萌建立了一个AJAX辅助这里<一href="http://stackoverflow.com/questions/5165948/problem-with-ajax-actionlink-helper-return-string">Problem与ajax.actionlink帮手,返回字符串。

他的code的伟大工程与没有paratmeters静态图像。

  @ Ajax.ImageActionLink(../../照片/儿童/ albersona1.jpg,索引,新{PN = PC},新AjaxOptions
    {
      UpdateTargetId =选择缩略图,
      InsertionMode = InsertionMode.Replace,
      HttpMethod =GET})
 

请问谁知道如何修改这个助手的URL.Action转化为阿贾克斯,使其处理动态图像和格式参数。

任何帮助非常AP preciated。

谢谢,乔

解决方案

 公共静态类ImageActionLinkHelper
{
    公共静态IHtmlString ImageActionLink(
        这AjaxHelper帮手,
        串IMAGEURL,
        串actionName,
        对象routeValues​​,
        对象htmlAttributes,
        AjaxOptions ajaxOptions
    )
    {
        VAR建设者=新TagBuilder(IMG);
        builder.MergeAttribute(src用户,IMAGEURL);
        builder.MergeAttributes(新RouteValueDictionary(htmlAttributes));
        VAR链接= helper.ActionLink([replaceme],actionName,routeValues​​,ajaxOptions);
        。VAR HTML = link.ToHtmlString()更换([replaceme],builder.ToString(TagRenderMode.SelfClosing));
        返回新HtmlString(HTML);
    }
}
 

然后:

  @ Ajax.ImageActionLink(
    Url.Content(〜/图片/+ photoFile [PC]),
    指数,
    新{PN = PC},
    新{ID =imgnbWIDTH =100像素,高度=150像素,ALT =照片},
    新AjaxOptions
    {
        UpdateTargetId =富
    }
)
 

I’m trying to change the following working code into Ajax.

   <a href="@Url.Action("Index", new { pn = pc })"> 
   <img src="@Url.Content("~/Photos/" + @photoFile[pc])", id = "imgnb" width = "100px" height = "150px" alt = "Photo" /></a>  <br />

The code needs to handle a string[] variable, @photoFile[pc]), and take formatting, ( id = "imgnb" width = "100px" height = "150px" alt = "Photo"). (imgnb is css, no image border)

Soe Moe built an Ajax helper here Problem with ajax.actionlink helper, return string.

His code works great with a static image with no paratmeters.

         @Ajax.ImageActionLink("../../Photos/Children/albersona1.jpg", "Index", new { pn = pc }, new AjaxOptions
    {
      UpdateTargetId = "Selected Thumbnail",
      InsertionMode = InsertionMode.Replace,
      HttpMethod = "GET" })

Would anyone know how to modify this helper to convert the URL.Action into Ajax so that it handles dynamic images and formatting parameters.

Any help greatly appreciated.

Thanks, Joe

解决方案

public static class ImageActionLinkHelper
{
    public static IHtmlString ImageActionLink(
        this AjaxHelper helper,
        string imageUrl,
        string actionName,
        object routeValues,
        object htmlAttributes,
        AjaxOptions ajaxOptions
    )
    {
        var builder = new TagBuilder("img");
        builder.MergeAttribute("src", imageUrl);
        builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
        var link = helper.ActionLink("[replaceme]", actionName, routeValues, ajaxOptions);
        var html = link.ToHtmlString().Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing));
        return new HtmlString(html);
    }
}

and then:

@Ajax.ImageActionLink(
    Url.Content("~/Photos/" + photoFile[pc]),
    "Index",
    new { pn = pc },
    new { id = "imgnb", width = "100px", height = "150px", alt = "Photo" },
    new AjaxOptions
    {
        UpdateTargetId = "foo"
    }
)

这篇关于与@ Ajax.ActionLink动态图像和格式化参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆