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、URL形式はどういう意味ですか? 'i'の値は、DataBaseのIDのパラメータとして渡します。 –
'Model.producturl' if-conditionは' GetProducts'メソッドへのリクエストが利用できる唯一の部分ですか? 'int'は' long'に自動的にフィットするので、 '@Url.Action'は問題ではありません。デベロッパーコンソールの[ネットワーク]タブで要求された画像のURL形式も確認します。 –