2017-08-22 11 views
0

私は以下の問題があります クリックすると部分的なビューを返すカスタムヘルパーを作成しました。カスタム静的htmlヘルパーにルート値を追加

class helpercontroller

列 "routevalues" は、1つの文字列(この場合property.Part.number)を受け取り、コントローラに送信するだけ。 コントローラーは自動的に文字列IDを送信中の値で埋めます。 複数の文字列を送信できます。 例:id = "123"、foo = "bar"。

@Ajax.ImageActionLink("/InternalDB/img/box/" + @property.Part.part_number + ".jpg",        
          "popup", 
          "85px", 
          "65px", 
          "PartialViewImageRotation",         
          property.Part.part_number, 
           new AjaxOptions 
           { 
            UpdateTargetId = "ImageRotation", 
            InsertionMode = InsertionMode.Replace, 
            HttpMethod = "GET" 
           }) 


    public static IHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, string altText,string width, string height, string actionName, 
     string routeValues, AjaxOptions ajaxOptions) 
    { 
     var builder = new TagBuilder("img"); 
     builder.MergeAttribute("src", imageUrl); 
     builder.MergeAttribute("alt", altText); 
     builder.MergeAttribute("width", width); 
     builder.MergeAttribute("height", height); 
     var link = helper.ActionLink("[replaceme]", actionName+"/"+routeValues, ajaxOptions).ToHtmlString(); 
     return MvcHtmlString.Create(link.Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing))); 
    } 



    public ActionResult PartialViewImageRotation(string routeValues,string id, string ImgWidthHTML5Viewer, string ImgHeightHTML5Viewer,string ImgWidthFlashPlayer, 
     string ImgHeightFlashPlayer, string ImgFloatPosition ,string ImgDivWidthRotatePlayer, string ImgDivPadding, string ImgWidthRotatePlayer, string ImgHeightRotatePlayer) 
    { 
     ViewBag.PartNumber = id; 

     ViewBag.ImgWidthHTML5Viewer = ImgWidthHTML5Viewer; 
     ViewBag.ImgHeightHTML5Viewer = ImgHeightHTML5Viewer; 

     ViewBag.ImgWidthFlashPlayer = ImgWidthFlashPlayer; 
     ViewBag.ImgHeightFlashPlayer = ImgHeightFlashPlayer; 
     ViewBag.ImgFloatPosition = ImgFloatPosition; 

     ViewBag.ImgDivWidthRotatePlayer = ImgDivWidthRotatePlayer; 
     ViewBag.ImgDivPadding = ImgDivPadding; 

     ViewBag.ImgWidthRotatePlayer = ImgWidthRotatePlayer; 
     ViewBag.ImgHeightRotatePlayer = ImgHeightRotatePlayer; 

     var firstImageRelativePath = "~/img/HTML/" + id + "/Profile.xml"; 
     var firstImageAbsolutePath = HttpContext.Server.MapPath(firstImageRelativePath); 
     ViewBag.FirstImageCheck = System.IO.File.Exists(firstImageAbsolutePath); 
     //possible problem : "\\" are doubled in the absolute path 

     var secondImageRelativePath = "~/img/SWF/" + id + "/" + id + ".swf"; 
     var secondImageAbsolutePath = HttpContext.Server.MapPath(secondImageRelativePath); 
     ViewBag.SecondImageCheck = System.IO.File.Exists(secondImageAbsolutePath); 

     return PartialView(); 
+0

この質問の中にコードを公開してください。 –

+0

実際にあなたのHTMLヘルパーはどこですか? –

+0

私のAjax.ImageActionLinkはPartialViewImageRotationを呼び出します。問題は、私は文字列idを値で満たすことしかできないということです。私は同様に値の残りを埋める必要があります – laz

答えて

0

これを解決する方法が見つかりました。私が行うために必要なすべては、いくつかのこと

public static IHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, string altText,string width, string height, string actionName, object routeValues, AjaxOptions ajaxOptions) { var builder = new TagBuilder("img"); builder.MergeAttribute("src", imageUrl); builder.MergeAttribute("alt", altText); builder.MergeAttribute("width", width); builder.MergeAttribute("height", height); var link = helper.ActionLink("[replaceme]", actionName, routeValues, ajaxOptions).ToHtmlString(); return MvcHtmlString.Create(link.Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing))); }

そして今、私は複数の値を送信することができますを変更することです。

関連する問題