如何Url.Action
在iframe
src
属性中使用该方法.喜欢
<iframe src = '<%=Url.Action("HelloWorld", "myController");%>' width = "100%" height="1000" frameBorder="0"></iframe>
Run Code Online (Sandbox Code Playgroud)
但它不能正常工作.它说所要求的内容不可用.
请帮我
在控制器中我有动作"GetPhoto":
public FileResult GetPhoto(int id)
{
...
}
Run Code Online (Sandbox Code Playgroud)
另外,我有Razor代码,我试图从模型中动态添加ID参数:
@model ISPIS.Models.KodFazeBiljke
...
<img src="@Url.Action("GetPhoto", new { id = model.KodFazeBiljkeId })" alt="" width="250" height="190"/>
Run Code Online (Sandbox Code Playgroud)
但是,编写"id = model.KodFazeBiljkeId"是不可能的,因为当前上下文中不存在模型.
有解决方案吗 谢谢!
当我尝试使用以下内容在Details页面模板中显示byte []数组图像时:
public FileContentResult RenderPhoto(byte[] photo)
{
// var array = (byte[])Session["photo"];
// return File(array, "image/jpeg");
return File(photo, "image/jpeg");
}
<img src="@Url.Action("RenderPhoto", Model.Photo)"/>
Run Code Online (Sandbox Code Playgroud)
照片为空.
如果我在会话中存储student.Photo:
//
// GET: /Student/Details/5
public ViewResult Details(int id)
{
Student student = db.Students.Find(id);
Session["photo"] = student.Photo;
return View(student);
}
Run Code Online (Sandbox Code Playgroud)
并尝试显示从Session(上面的注释行)中检索值的图像.
为什么我在第一种情况下获得空值?
将学生传递给View in后ViewResult Details(int id)
,Model.Photo
不再保留该值了吗?
我在 asp.net mvc2 项目中创建了 Html helper 类:
public static class CaptionExtensions
{
public static string Captions(this HtmlHelper helper, Captions captions)
{
var sb = new StringBuilder();
sb.AppendLine("<ul>");
foreach (var caption in captions)
{
// var url = Url.Action("CaptionCategory", new {id = caption.Code} )
sb.AppendLine("<li>");
sb.AppendLine( "<a href="+ url + ">");
sb.AppendLine( caption);
sb.AppendLine( "</a>");
sb.AppendLine("</li>");
}
sb.AppendLine("</ul>");
return sb.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
我需要生成与注释行中的方式类似的 url。注释代码是我在控制器类中的做法,但这是辅助类(静态上下文)。任何帮助???
url-action ×4
asp.net-mvc ×2
c# ×1
database ×1
html-helper ×1
iframe ×1
image ×1
razor ×1
routevalues ×1