我有 mvc 3 应用程序,其中在会话对象中我将我需要的所有值作为参数来执行存储过程。
如果 userAction 是更新,则执行存储过程。
public ActionResult Index(string userAction)
{
if(Session["Mappings"] != null)
ViewData["Message"] = "Mapping web grid";
if (Session["PricingSecurities"] == null)
Session["PricingSecurities"] = objRepository.GetPricingSecurityID();
if (Session["Cusips"] == null)
Session["Cusips"] = objRepository.GetCUSIP();
SecurityMappingModel objModel = null;
mappings = (List<SecurityMappingModel>)Session["Mappings"];
objModel = new SecurityMappingModel();
if (userAction == "Update" )
{
//please tell me how can i take values from Session[Mappings] and pass it to stored procedure?
//i'm trying this code
//foreach (var item in Session)
//{objModel.Cusips = (List<SelectListItem>)Session["Mappings"];
//I did function import here (import my sp in model)using EF name
//ExecuteMappingsp.
//dbContext.ExecuteMappingsp(need to pass parameter);
//} //i know wrong code but how to fix this??
// PLEASE HELP ME TO RETRIEVE SESSION VALUES
return RedirectToAction("Index");
}
objModel.PricingSecirities = (List<SelectListItem>)Session["PricingSecurities"];
objModel.Cusips = (List<SelectListItem>)Session["Cusips"];
ViewBag.Mappings = mappings;
return View(objModel);
}
如何从 Session[Mappings] 中获取值并将其传递给存储过程?