向自定义静态 html 助手添加更多路由值
add more route values to custom static html helper
我有以下问题
我创建了自定义助手,returns 单击时显示部分视图。
class helper
controller
字符串"routevalues"只需要一个字符串(在本例中为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();
我找到了解决这个问题的方法。我需要做的就是改变一些东西
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)));
}
现在我可以发送多个值。
我有以下问题 我创建了自定义助手,returns 单击时显示部分视图。
class helper controller
字符串"routevalues"只需要一个字符串(在本例中为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();
我找到了解决这个问题的方法。我需要做的就是改变一些东西
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)));
}
现在我可以发送多个值。