Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
int id=1;
public PartialViewResult ViewQuestions()
        {
            
            string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
            GetQuestions getquest = new GetQuestions();
            try
            {
                SqlConnection con = new SqlConnection(constr);
                con.Open();
                SqlCommand cmd = new SqlCommand("Select q.QuestID,q.QImage,q.Question,o.FOption,o.SOption,o.TOption,o.FROption from QuestionSet as q join OptionSet as o on q.QuestID=o.QuestID where q.QuestID=@questid ", con);
                cmd.Parameters.AddWithValue("@questid", id);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    getquest.QuestID = dr.GetInt32(0);
                    getquest.QuestImage = dr.GetString(1);
                    getquest.Question = dr.GetString(2);
                    dr.Close();
                    SqlCommand cmd1 = new SqlCommand("Select Foption,Soption,Toption,FRoption from Optionset where QuestID=@questid ", con);
                    cmd1.Parameters.AddWithValue("@questid", id);
                    SqlDataReader dr1 = cmd1.ExecuteReader();
                    if (dr1.Read())
                    {
                        List<Options> opt = new List<Options>();
                        opt.Add(new Options { Option1 = dr1.GetString(0) });
                        opt.Add(new Options { Option1 = dr1.GetString(1) });
                        opt.Add(new Options { Option1 = dr1.GetString(2) });
                        opt.Add(new Options { Option1 = dr1.GetString(3) });
                        getquest.Options = opt;
                    }
                    dr1.Close();
                    
                    
                }


            }
            catch (Exception ex)
            {

            }
            return PartialView(getquest);
        }
        [HttpPost]
        public RedirectToRouteResult Forward()
        {
            
            int ID = Convert.ToInt32(Request.Form["QuestID"]);
            id = ID + 1;
            
            
            return RedirectToAction("ViewQuestions");
        }


What I have tried:

I try to update the value of id each time when user press the "Next" button from view page . I assign the post method "Forward" for that?

Thanks in advance.
Posted
Updated 12-Jul-16 1:05am

1 solution

Pass id as argument to the ViewQuestion() method.
And on ex=ach click call ViewQuestion(int id) with id= incremented value.
Keep id in code behind layer
 
Share this answer
 
Comments
Binit_Bihari 12-Jul-16 7:19am    
but i don't want to show it in my url
RebelStar 13-Jul-16 1:03am    
then send id using base64 encoded querystrings : url?q=yourbase64id
or
as base64 encoded parameter: ViewQustion(string youbase64id)

and then decode it back to get int id
Binit_Bihari 13-Jul-16 6:06am    
yeah this should be good idea. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900