将对象数据从控制器传递到 MVC C# 中的部分视图
Pass object data from controller to Partial View in MVC C#
我有 class CourseInstanceModel 并且在 Feed class 我正在阅读所有课程,然后是 LINQ 查询以获取数据库中 URL 字段为空然后传回的所有课程控制器;存储在对象 effectedCourseInstances 中。我需要在用户接受或拒绝之前显示到页面(查看)的新列表。
我正在努力将 effectedCourseInstances 传递给控制器的部分视图????
供稿 Class
public List<CourseInstanceModel> ProcessAllCoursesApplicationURL(CourseApplicationsURLFeed_Model _obj)
{
using(var _uof = new Courses_UnitOfWork())
{
var ListOfCoursesInstances = _uof.CourseInstances_Repository.GetAll();
var _listOfCoursesWithoutURL = (from b in ListOfCoursesInstances
where b.ApplicationURL == null
select b).ToList();
return _listOfCoursesWithoutURL;
}
}
控制器class
[HttpGet]
public ActionResult ProcessCourseApplicationURL()
{
return PartialView("ProcessCourseApplicationURL_Partial");
}
[HttpPost]
public ActionResult ProcessCourseApplicationURL(CourseApplicationsURLFeed_Model obj)
{
try
{
if (ModelState.IsValid)
{
_effectedCourseInstances = _coursesServices.ProcessAllCoursesApplicationURL(obj);
}
}
catch (DataException ex)
{
ModelState.AddModelError("", "Unable To Process Courses Application URL from CID DB" + ex);
}
return PartialView("CourseApplicationURLTest_Partial");
????? need to pass effectedCourseInstances data to Partial View?????
} //end
查看
@model CID_App.DAL.Model.CourseInstanceModel
read effectedCourseInstances of CourseInstanceModel class here ....
您需要将模型传递给 PartialView 函数。该视图还需要接受 CourseInstanceModel
的列表
查看
@model List<CID_App.DAL.Model.CourseInstanceModel>
控制器
[HttpPost]
public ActionResult ProcessCourseApplicationURL(CourseApplicationsURLFeed_Model obj)
{
try
{
if (ModelState.IsValid)
{
_effectedCourseInstances = _coursesServices.ProcessAllCoursesApplicationURL(obj);
}
}
catch (DataException ex)
{
ModelState.AddModelError("", "Unable To Process Courses Application URL from CID DB" + ex);
}
return PartialView("CourseApplicationURLTest_Partial", _effectedCourseInstances);
}
@toxic :View 仅用于呈现您的数据模型(来自控制器的return)&在您的情况下,您正在呈现模型的列表数据类型,因此视图将只接受列表。
@Oliver 是对的,感谢您分享您的知识。
我有 class CourseInstanceModel 并且在 Feed class 我正在阅读所有课程,然后是 LINQ 查询以获取数据库中 URL 字段为空然后传回的所有课程控制器;存储在对象 effectedCourseInstances 中。我需要在用户接受或拒绝之前显示到页面(查看)的新列表。
我正在努力将 effectedCourseInstances 传递给控制器的部分视图????
供稿 Class
public List<CourseInstanceModel> ProcessAllCoursesApplicationURL(CourseApplicationsURLFeed_Model _obj)
{
using(var _uof = new Courses_UnitOfWork())
{
var ListOfCoursesInstances = _uof.CourseInstances_Repository.GetAll();
var _listOfCoursesWithoutURL = (from b in ListOfCoursesInstances
where b.ApplicationURL == null
select b).ToList();
return _listOfCoursesWithoutURL;
}
}
控制器class
[HttpGet]
public ActionResult ProcessCourseApplicationURL()
{
return PartialView("ProcessCourseApplicationURL_Partial");
}
[HttpPost]
public ActionResult ProcessCourseApplicationURL(CourseApplicationsURLFeed_Model obj)
{
try
{
if (ModelState.IsValid)
{
_effectedCourseInstances = _coursesServices.ProcessAllCoursesApplicationURL(obj);
}
}
catch (DataException ex)
{
ModelState.AddModelError("", "Unable To Process Courses Application URL from CID DB" + ex);
}
return PartialView("CourseApplicationURLTest_Partial");
????? need to pass effectedCourseInstances data to Partial View?????
} //end
查看
@model CID_App.DAL.Model.CourseInstanceModel
read effectedCourseInstances of CourseInstanceModel class here ....
您需要将模型传递给 PartialView 函数。该视图还需要接受 CourseInstanceModel
查看
@model List<CID_App.DAL.Model.CourseInstanceModel>
控制器
[HttpPost]
public ActionResult ProcessCourseApplicationURL(CourseApplicationsURLFeed_Model obj)
{
try
{
if (ModelState.IsValid)
{
_effectedCourseInstances = _coursesServices.ProcessAllCoursesApplicationURL(obj);
}
}
catch (DataException ex)
{
ModelState.AddModelError("", "Unable To Process Courses Application URL from CID DB" + ex);
}
return PartialView("CourseApplicationURLTest_Partial", _effectedCourseInstances);
}
@toxic :View 仅用于呈现您的数据模型(来自控制器的return)&在您的情况下,您正在呈现模型的列表数据类型,因此视图将只接受列表。 @Oliver 是对的,感谢您分享您的知识。