0

I have an XML file with several environment names and corresponding URL to the environment name. Requirement is: 1. display the environment names in a dropdownlist 2. select any environment name in dropdownlist. 3. Click Navigate link below dropdown button. 4. The page should be navigated to particular URL, which the environment name belongs to.

EX: (from XML File)

I want to fetch "name" & "LMHost" .

I completed upto creating dropdownlist. Binding environment name inside dropdownlist. But i dunno how to navigate it to particular URL.

My Controller Code

var xDoc = XDocument.Load(fileName);
                    IEnumerable<XElement> envGroups = from xmlDoc in xDoc.Descendants().Elements("environment")
                                                      select xmlDoc;
                    model.EnvironmentName = from envName in envGroups.Attributes("name")
                                            select new SelectListItem
                                            {
                                                Text = envName.Value,
                                                Value = envName.Value.ToString(),
                                               Selected = (envName.Equals(envName))
                                            };
                    return View(model); 

View Code

    <%=Html.DropDownList("EnvironmentName", new SelectList      (Model.EnvironmentName, "Value" , "Text")) %>

Model Code

public IEnumerable _environmentName;

    [DisplayName("EnvironmentName")]
    public IEnumerable<SelectListItem> EnvironmentName
    {
        get
        {
            if (_environmentName == null)
                _environmentName = new List<SelectListItem>();
            return _environmentName;
        }

        set { _environmentName = value; }
    }

Kindly help me. I find difficult to navigate the environment names to its particular URL

1
  • If you have the url I would recommend using jquery window.location = url Commented Sep 9, 2014 at 14:40

1 Answer 1

0

As mentioned above, window.location will work

Include jquery on your page, and add a button or anchor to your page with the onclick action:

    window.location=$('#EnvironmentName').val();

You can prefix/suffix the location to create the correct path e.g.:

    window.location='http://yoursitepath/' +  $('#EnvironmentName').val() + '.html';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.