English 中文(简体)
是否需要将会议目标中的数值重新分类,在mvc3中采用代谢物?
原标题:Need to retrive values from Session object using foreach in mvc3?

我有第3号申请,在会议上反对将我所需要的所有价值作为执行储存程序参数。

如果用户行动得到更新,则执行所储存的程序。

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" ) 
    { 
        //help me to fix this code 

        //foreach (var item in Session)
        //{Session["Mappings"] //NEED FIX HERE
        //}
        // PLEASE HELP ME TO RETRIEVE SESSION VALUES
        return RedirectToAction("Index"); 
    } 
    return View(objModel); 
} 

HOW CAN I RETRIEVE ALLVALUES OF Session [“Mappings”] it is held 3entries 3ids,3cusips,3calculation

问题回答

简短的回答是不要将<代码>var<>/code>作为你的列举类型,而是使用<代码>object。

foreach (obj item in Session) {
    if (item is CUSIP) {
        // CUSIP processing
    } else if (item is PricingSecurity) {
        //Pricing security processing
    } //etc.
}

如你所知,这种做法的问题是,为了对其采取任何习俗行动,你必须检验每一物体的类型。 更好的想法是创建你自己的班子,以储存在本届会议上:

public class SessionData()
{
    List<CUSIP> Cusips {get;set;}
    List<PricingSecurity> PricingSecurities {get;set;}

    public SessionData()
    {
        // Initialize the lists so they are never null
        this.Cusips = new List<CUSIP>();
        this.PricingSecurities = new List<PricingSecurity>();
    }
}

然后,你只能穿透每个清单的特性,并采取任何必要的行动。





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签