2017-08-22 2 views
0

J'ai le problème suivant J'ai créé l'aide personnalisée qui retourne une vue partielle lorsque vous cliquez dessus.ajouter plus de valeurs de route à helper html statique personnalisé

class helper controller

la chaîne "routevalues" ne prend une corde (dans ce cas property.Part.number) et il envoie au contrôleur. Le contrôleur remplira automatiquement l'identifiant de chaîne avec la valeur que j'envoie. Je souhaite pouvoir envoyer plusieurs chaînes. Exemple: 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

Veuillez publier le code dans cette question. –

+0

Où est réellement votre html-helper? –

+0

mon Ajax.ImageActionLink appellera le PartialViewImageRotation. Le problème est que je ne peux que remplir l'identifiant de chaîne avec une valeur. J'ai besoin de remplir le reste des valeurs ainsi – laz

Répondre

0

J'ai trouvé un moyen de résoudre ce problème. Tout ce que je devais faire est de changer quelques choses

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))); }

Et maintenant, je peux envoyer des valeurs multiples.