c# - Grabbing the ID value from a drop down list in mvc -


the big picture this: when user logs in, can select "organization" log drop down list, has unique id # each organization. when user logs in, want grab id # people table. problem is, person in table twice, this:

id name     orgid 1  brandon  1 2  brandon  2 

so, grab appropriate person id, need check against orgid also. here i've got in method:

public actionresult index()     {         viewbag.organization = new selectlist(db.organizations, "orgid", "orgname");         return view();     } 

here post method:

     [httppost, actionname("submit")]     public actionresult submitpost(string loginnid, string loginpassword, loginviewmodel model)     {         //create new instance of activedirectoryhelper access methods         activedirectoryhelper login = new activedirectoryhelper();          //get username , password forms         string username = loginnid;         string password = loginpassword;         int orgid = model.organizations.orgid;          //viewbag initialization error message         viewbag.numtimes = 0;         viewbag.message = "error logging in, please try again.";          //ldap authentication         bool loginpassed = login.isauthenticated(username, password);         int organization = organizations.orgid;          //if authentication success enter site, otherwise return error message         if (loginpassed == true)         {             //grabs 1 person people model nid == username             var peoplemodel = db.people.single(g => g.nid == username);              //grabs peopleid use in making session variable             var peopleid = peoplemodel.peopleid;              //sets session variable used logged in person's id             session["peopleid"] = peopleid;             return view("loginsuccess");         }          else         {             viewbag.numtimes = 1;             viewbag.organization = new selectlist(db.organizations, "orgid", "orgname", organizations.orgid);             return view("index");         }     } 

here viewmodel:

    public class loginviewmodel {     public music.models.organizations organizations { get; set; } } 

any ideas how can organization's id # , select unique person id # can make session variable? much!

edit: updated code reflect changes i've made answers provided.

you can create class of session information id capture after login. have login perform login verification, route session info page select organization based off users available organization. pass helper class stores in session information.

edit

after re-reading question can provide list of organizations @ login page , verification against whatever doing , ensuring matches organization 1 screen.

public class logincredential {     public string username { get; set; }     public string password { get; set; }     public int organizationid { get; set; } }  public actionresult index() {     viewbag.organizations = new selectlist(db.organizations, "orgid", "orgname");     return view(); } 

make model login page login credential

@model myproject.models.logincredential 

then when submit form pass in selected options.

[httppost, actionname("submit")] public actionresult login(logincredential credentials) {         string username = credentials.username ;     string password = credentials.password ;     int organizationid = credentials.organizationid;     ///  rest of code goes here } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -