Redirect users to a view using Switch case in asp.net MVC?


I want to redirect the users to certain pages on the basis of their rating. How can I use a switch case in C# ASP.NET MVC to do this? Please give me suggestions with some code part.


Asked by:- DixonCh
1
: 5607 At:- 9/12/2017 12:23:44 AM
C# Asp.net mvc switch-case







1 Answers
profileImage Answered by:- vikas_jk

You can write switch case in C# controller ActionMethod like this

//You can get data in any way using Ajax or posting a form
//in this example i assume posting a form data
public ActionResult GetViewBasedOnRating(FormCollection collection)
{
  int rating = collection["rating"];
  
  switch (rating) 
  {
                case 1:
                    //redirect to view which has rating 1 data

                case 2:
                    //redirect to view which has rating 2 data

                case 3:
                   //redirect to view which has rating 3 data

                default:
                 //redirect to default view
                    break;
   }

}

the above code redirect's user taking the rating value from the form, then code check's which rating value is passed, according to it the case is selected and the user is redirected to that view.

Hope this helps, let me know using the comment section of answer, thanks

0
At:- 9/12/2017 5:50:19 AM
Thank you so much for your answer. It helped me alot. 1
By : DixonCh - at :- 9/12/2017 12:49:30 PM
great, thanks 0
By : vikas_jk - at :- 9/13/2017 11:06:30 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use