Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a drpodown country. if i had select, India then i want to redirect the page to homepage. how can it possible in mvc?


//in cshtml-view page i have coding like this
<div class="editor-label">
@Html.LabelFor(model => model.PropertyTypePropertyTypeId)
</div>
<div class="editor-field">
@Html.DropDownList("PropertyTypePropertyTypeId",string.Empty)
@Html.ValidationMessageFor(model => model.PropertyTypePropertyTypeId)
</div>

// in controller

public ActionResult Create()
{
ViewBag.PropertyTypePropertyTypeId = new SelectList(context.PropertyTypes, "PropertyTypeId", "PTypeName");
return View();
}
where i want to write this codes? Can anyone help me?
Posted
Updated 15-Jul-11 19:29pm
v3
Comments
Salmen Essridi 15-Jul-11 6:57am    
Can you more explain ?
Salmen Essridi 15-Jul-11 6:59am    
the dropdown is it in a partial view?

//create a method to get Dropdown values 

public ViewResult Index()
        {
            var categories = from c in db.category_master select c;
            ViewData["Categories"] = new SelectList(categories, "ID", "Name");
            return View(db.akshay_category_master.ToList());

        }

// In view 

@Html.DropDownList("Categories", ViewBag.applicationList as SelectList, "Select", new { onchange = "javascript:sendParam();" })

 //Javascript Function 

<script type="text/javascript">
    function sendParam() {

        window.location = "Category/CategoryDetails/" + jQuery("#Categories").val();

    }

  // that Method in Controller

  public ViewResult CategoryDetails(int id)
        {

            var Result = from C in db.category_master
                         where C.id == id
                         select C;
            return View("CategoryDetails", Result.ToList());
          
        } 
 
Share this answer
 
try to apply this example.

C#
@Html.DropDownList(
    "PropertyTypePropertyTypeId",
     ViewData["Categories"], // it need to be casted  i think 
    null,
    new { onchange = "document.location.href = '/Controller/MyAction?country=' + this.options[this.selectedIndex].value;" })


you have to create an action in the controller.

SQL
public ActionResult MyAction(string country ) 
            {
                 // return the adequate view depending on the country argument 
                  .....
            }


and good luck.
 
Share this answer
 
v2
Comments
Aswathi Narayan 16-Jul-11 1:03am    
Thank u 4 ur reply...while executing my project with this coding the error message is showing like this.. The name 'listitems' does not exist in the current context.. Can u help me
Salmen Essridi 16-Jul-11 11:23am    
you have to use your own list of items. what you have in the ViewData["Categories"] i think.
I just give you an idea.
Aswathi Narayan 18-Jul-11 8:37am    
Is MyAction is a controller page(ie .cs page) or function name??? i have a controller page called PropertyMainController.cs and while running my url is http://localhost:50888/Controller/PropertyMainController.cs?country=1. am getting id but error message is showing like this
The resource cannot be found.
Salmen Essridi 18-Jul-11 11:37am    
see my solution
Repak5 10-Oct-11 5:13am    
Thank you! This working is very nice!
MyAction is the function name in the controller like i said

also if all things are well done
you have to use this URL

http://localhost:50888/PropertyMainController/MyAction?country=1

without the .cs

i see that you still don't understand the basics of routing in MVC.net

so i advaice you to see this link

http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs[^]

also

http://www.asp.net/mvc[^]

good luck.
 
Share this answer
 
Comments
Aswathi Narayan 19-Jul-11 5:44am    
Thank u
Salmen Essridi 19-Jul-11 5:55am    
you are welcome, if you find it useful accept it or upvote it :).

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