Asp.net mvc 3 如何将模型的obejct传递到现有视图?
我正在MVC3中创建应用程序。我有一个ConferenceController,其创建视图如下: 命名空间配置器.控制器 { 公共类ConferenceController:BaseControllerAsp.net mvc 3 如何将模型的obejct传递到现有视图?,asp.net-mvc-3,Asp.net Mvc 3,我正在MVC3中创建应用程序。我有一个ConferenceController,其创建视图如下: 命名空间配置器.控制器 { 公共类ConferenceController:BaseController { public ActionResult Create() { return View(new ConferenceModel()); } } } 我在这个创建视图上有一个下拉列表,其中包含产品列表。在选择特定产品时,我通过以下方
{
public ActionResult Create()
{
return View(new ConferenceModel());
}
}
}
我在这个创建视图上有一个下拉列表,其中包含产品列表。在选择特定产品时,我通过以下方式获得ConferenceModel对象中该产品的详细信息:
要获取产品ID,我正在使用jquery:
$ddlProductList.changefunction{
$.get'/Conference/GetProductDetailByProductID/',{ProductID:$this.val},函数响应{
};
};
在ConferenceController中创建了一个函数,当下拉更改事件触发时将调用该函数
公共操作结果GetProductDetailByProductId字符串ProductID
{
返回ViewConferenceModel.GetProductDetailByProductIDProductID;
}
在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));
}
我的问题是,我可以使用现有的创建视图来显示数据,还是必须创建另一个名为GetProductDetailByProductID的视图
任何人都知道这个问题,请帮助我。视图方法有一个重载,允许您指定视图名称: 返回ViewCreate,ConferenceModel.GetProductDetailByProductIDProductID
此处的文档:您可以使用
return View("viewname", model)
默认情况下,操作的名称用作视图名称。您希望使用jQuery从客户端脚本获取产品详细信息 而不是回答:
public ActionResult GetProductDetailByProductID(string ProductID)
{
return View(ConferenceModel.GetProductDetailByProductID(ProductID));
}
为什么不简单地返回一个JSON字符串呢
public JsonResult GetProductDetailByProductID(string ProductID)
{
return this.Json(ConferenceModel.GetProductDetailByProductID(ProductID));
}