简体   繁体   中英

How to pass values to parameter to call stored procedure from MVC

This is MVC C#. I have stored procedure called uspMarket_test . I need to pass parameter called session to this SP.

I am writhing this code in controller . Here sess contains values of session which i am passing.

public ActionResult Index(string sess)
    {

        var permissions = new Accept();
        permissions.permissions(sess);



        return View();
    }

In terms.cs, i am using :

public void permissions(string sess)
    {
        using (var ctx2 = new market_Entities())
        {
         //Here i need to assign sess = session, so value of sess will be equal to session string.But dont know how to do this.

      ctx2.uspMarket_test(new ObjectParameter("UserID", typeof(int)),"session", new ObjectParameter("Login",typeof(short)));
            ctx2.SaveChanges();
        }
    }

Here problem i am having is, second parameter session. I need to assign sess value to session parameter, so when i pass session to SP, it will take sess values. but i dont know how to assign this.

Try this.

Session["YourIndexName"] = sess;

or

Session[0] = sess; //using whatever zero based index is appropriate for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM