0

I have created an web application of Tenders with a DropDownList of companies' name. These names I take from a specific directory, put into a array and copy to a List and I added the string "-Add new-" in order to create an action when this option is chosen by the user.

First question: How can I create a action that opens a little window with a text box when the user chooses "-Add new-", and after writing the name and clicking in "Add", it creates a new folder in my "\My network directory\"?

Second question: As I said before, the DropDownList of companies' name is from "\My network directory\", how can I pass the value chosen by the user (the company name) and shows in another DropDownList the sub-directories of the folder (company) chosen?

//The controller
public class TenderController : Controller
{
    //
    // GET: /Tender/
    public ActionResult AddNewTender()
    {
        //Get companies directory and put it into a string array
        string[] compNameArray = Directory.GetDirectories(@"//My network directory\");
        int i = 0;
        foreach (string txtName in compNameArray)
        {
            //Copy to another string every directory name only with the las name file (the company name)
            string txtDirName = txtName.Substring(txtName.LastIndexOf(@"\") + 1);
            //Update the companies name array with the companies name only
            compNameArray[i] = txtDirName;
            i++;
        }
        //Copy the companies name array to a list
        List<string> compList = new List<string>(compNameArray);
        //Remove from the list the names above
        compList.Remove("New folder");
        //Add the "add new" option to the list
        compList.Add("-Add new-");
        ViewBag.ListOfCompanies = compList;
        return View();
    }

The view:

            <td dir="rtl">
                @Html.DropDownList("companyName", new SelectList(ViewBag.ListOfCompanies, Model))
            </td>          

The page: It looks like this

3
  • you should use javascript for this case Commented Jan 12, 2016 at 15:43
  • I am not so good with javascript... Can you explain how exactly? Commented Jan 13, 2016 at 9:23
  • You should check some tutorials. like this Commented Jan 13, 2016 at 9:24

1 Answer 1

0

First question:

Run javascript after dropdownlist change.

In the Javascript you should check the dropdown value.

Then you can create a button from the Javascript.

After clicking "add", create an action in the controller to create the new folder.

Second question:

The same trick as the first question, use onchange event to run Javascript. In the Javascript you can add values to dropdownlists.

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.