我想基于TextBox
输入在我的视图中显示大量图像。基于文本框输入显示图像
我有这个Controller
:
public ActionResult GetProducts(long id, Search obj)
{
GetSearchByDropdowns();
using (ThBEntities1 db = new ThBEntities1())
{
if (id == null) {
return View("Index");
}
byte[] image = db.Searches.Where(x => x.SearchTextBox == x.Product).SingleOrDefault().producturl;
var stream = new MemoryStream(image.ToArray());
return new FileStreamResult(stream, "image/jpeg");
}
return View("~/Views/Search/Index.cshtml", obj);
}
在我看来
if (Model.producturl != null)
{
for (int i = 0; i < 6; i++)--I only have 6 records
{
<img src='@Url.Action("GetProducts", "Search", new{ id = i })' />
}
}
而且我的模型
public partial class Search
{
public long ID { get; set; }
public string Product { get; set; }
public byte[] producturl { get; set; }
}
我收到此错误:
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int64' for method 'System.Web.Mvc.ActionResult GetProducts(Int64, ThunderBird.Search)' in 'ThunderBird.Controllers.SearchController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
我知道它来自GetProducts(long id, Search obj)
,但是如何将视图中的模型作为参数传递?
您是否检查浏览器中呈现的URL格式是什么?它对'i'具有约束力吗? –
@SivaGopal,你的网址格式是什么意思?来自'i'的值我将它作为DataBase中ID的参数传递。 –
是否只有'Model.producturl'条件是GetProducts方法可用的唯一部分?由于'int'可能自动适合'long',因此'@ Url.Action'不应该成为问题。还请在开发者控制台的“网络”标签中查看请求的图片网址 –