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.
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
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly