我无法弄清楚将模型数据发送到部分视图的 Razor 语法,该部分视图根据我需要传递给它的 ID 显示图像。我收到以下错误消息:
'System.Web.Helpers.WebGrid.Column(string, string, System.Func, string, bool)' 的最佳重载方法匹配有一些无效参数
主视图中的代码:
@model IEnumerable<ProjectMVC.Models.Image_result>
@grid.GetHtml(tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns
(
grid.Column(header: "Imageview", format: (item) => Html.Partial("ShowImage2", item))
)
);
Partial view:
@model ProjectMVC.Models.Image_result
@using System.Data.SqlClient;
@using System.Configuration;
@{
ViewBag.Title = "ShowImage2";
}
@{
var id = Model.id;
if(id > 0)
{
string sqlText = "SELECT * FROM Images WHERE img_pk = " + id;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
SqlCommand command = new SqlCommand(sqlText, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
Response.BinaryWrite((byte[])dr["img_data"]);
}
connection.Close();
}
}
任何帮助,将不胜感激!