【发布时间】:2011-04-15 07:45:44
【问题描述】:
我正在 MVC3 中创建应用程序。我有一个会议控制器,它有一个像这样的 Create() 视图:
命名空间配置器.Controllers { 公共类 ConferenceController : BaseController
{
public ActionResult Create()
{
return View(new ConferenceModel());
}
}
}
我在此创建视图上有一个下拉列表,其中包含产品列表。在选择特定产品时,我以这种方式在 ConferenceModel 的对象中获取该产品的详细信息:
- 要获取我使用 jquery 的产品 ID:
$("#ddlProductList").change(function () { $.get('/Conference/GetProductDetailByProductID/', { ProductID: $(this).val() }, function (response) { }); });
-
在 ConferenceController 中创建了一个函数,当下拉更改事件触发时将调用该函数。
public ActionResult GetProductDetailByProductID(string ProductID) { 返回视图(ConferenceModel.GetProductDetailByProductID(ProductID)); }
-
在 ConferenceModel 中创建一个函数,根据 ProductID 从数据库中获取产品详细信息:
public static ConferenceModel GetProductDetailByProductID(string ProductID) { ConferenceModel obj = new ConferenceModel(); // Logic goes here to to get the details of product on the basis of productID and returning the object. return obj; } -
当我尝试检查此功能时,它给我的错误是它没有找到任何视图来显示此部分 COnferenceController 页面上的数据:
public ActionResult GetProductDetailByProductID(string ProductID) { return View(ConferenceModel.GetProductDetailByProductID(ProductID)); } 我的问题是我是否可以使用现有的 Create() 视图来显示数据,或者我必须使用以下名称创建另一个视图:GetProductDetailByProductID()
谁知道这个问题,请帮助我。
【问题讨论】:
标签: asp.net-mvc-3