Hi
I have a modal popup in my view that asks for information, I would like the info obtained from that view to be sent to the controller. From the controller it should be sent to a .txt file and then also displayed on a page.
If I use the method below with a button and textbox it works fine, but the minute I try to use a modal instead it wont pass through the info in the textbox modal popup. Please help. Also is there a way to di it without using ajax as I have never used it before.
Thanks!
[HttpPost]
public ActionResult Index(string addCategory)
{
string path = Server.MapPath("~/App_Data/Categories.txt");
using (StreamWriter sw = System.IO.File.CreateText(path))
{
sw.WriteLine(addCategory);
}
ViewBag.Fullname = addCategory;
return View();
}
@using (Html.BeginForm("Index", "List", FormMethod.Post))
{ <!-- Add Modal -->
<form>
<div class="modal fade" id="mdl-add" tabindex="-1" role="dialog" aria-labelledby="mdl-add-lbl" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header bg-dark text-white">
<h5 class="modal-title" id="mdl-add-lbl">Add Category</h5>
<button type="button" class="close text-light" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<!-- Category Input Container -->
<label for="name-input">Description</label>
<input type="text" class="form-control" id="addCategory" name="addCategory">
</div>
</div>
<div class="modal-footer bg-dark">
<button type="button" id="btnSubmit" class="btn btn-primary" data-dismiss="modal">Submit</button>
<button type="button" id="btnDismiss" class="btn btn-primary" data-dismiss="modal">Back</button>
</div>
</div>
</div>
</div>
</form>