我正在尝试将〜/ folder / pages中的选定项目显示到asp.net 2015中的根页面名称产品,我已经在页面中显示了所有项目,但是当我调用模型类时出现错误“{ {1}}“并且很少有错误,例如
错误CS1503参数1:`无法转换 'SAIT_Electronics.Pages.Product'到'SAIT_Electronics.Product
cannot implicitly convert type
here is attached error picture of asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SAIT_Electronics.Models;
using System.Collections;
using System.Management;
using SAIT_Electronics.Pages;
namespace SAIT_Electronics.Pages
{
public partial class Product : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Fillpage();
}
private void Fillpage()
{
//get selected products data
if(!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
int id = Convert.ToInt32(Request.QueryString["id"]);
productmodel model = new productmodel();
Product product = model.GetProduct(id);
//fill page with data
lblPrice.Text = "Price per unit : <br/>$" + product.Price;
lblTitle.Text = product.Name;
lblDescription.Text = product.Description;
lblItemNr.Text = id.ToString();
imgProduct.ImageUrl = "~/Images/Products/" + product.Image;
//fill amount dropdownlist with number 1 -10
int[] amount = Enumerable.Range(1, 10).ToArray();
ddlAmount.DataSource = amount;
ddlAmount.AppendDataBoundItems = true;
ddlAmount.DataBind();
}
}
}
}
答案 0 :(得分:0)
此行中的Product
类型
Product product = model.GetProduct(id);
是你现在所在的Product
课程,因此是SAIT_Electronics.Pages.Product
。试试这个:
SAIT_Electronics.Product product = model.GetProduct(id);
或者只是这个:
var product = model.GetProduct(id);
您应该在ManageProducts.aspx.cs文件中执行相同的操作。无论您在何处定义Product
类型的变量,请将Product
替换为SAIT_Electronics.Product
。例如,第39行变为:
SAIT_Electronics.Product product = CreateProduct();
第61,106和108行也是如此。