Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

What is wrong with my ChildAction and razor view

$
0
0
I have this child action in a controller
 
[ChildActionOnly]
public ActionResult GetImage(int id)
{
var photo = _Db.Photozs.Single(p => p.PhotozId == id);
string path = Server.MapPath("~/Photo"+photo.Url);
fs = new FileStream(path, FileMode.Open);
return new FileStreamResult(fs, photo.ContentType);
}
 

 

 
My razor view is :
 
@model IEnumerable
 
@{
ViewBag.Title = "Index";
}
 

 
@foreach (var item in Model)
{

<img class="img-polaroid" src="@Url.Action("GetImage",new{id=item.PhotozId})"/>
@item.Caption
}
 

The problem I'm having is that when I remove d ChildActionOnlyAttribute from GetImage action the image renders in the view but when I add it it does not. I want this action to b child so it cannot be invoked directly by the user. Thanks

Viewing all articles
Browse latest Browse all 3938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>