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

Daniel
  • 15
  • 1
  • 5

1 Answers1

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.

Community
  • 1
  • 1
Reginiano
  • 62
  • 10