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