I'm moving from php to asp.net. I created a simple page with a dropdown, a textarea (tinyMCE), and a button to save the text into the database. The save button opens a bootstrap modal to enter the name of the form that I want to save.
@model FormsCreator.Models.ModelView.ListFormsCreator
@{
Layout = "";
}
<html>
<head>
<script src="~/Scripts/jquery-3.2.1.min.js"></script>
<script src="~/Scripts/tinymce/tinymce.min.js"></script>
<script src="~/Scripts/JS/formsCreator.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<form>
<br/><br />
<div class="form-group col-sm-3">
@Html.DropDownListFor(m => m.Forms, new SelectList(Model.Forms, "FormsCreatorID", "FormName"),
"Select a Form", new { @class = "form-control" })
</div>
<br/><br/>
<div class="form-group col-sm-12">
<textarea class="form-control" id="mytextarea" name="mytextarea">Next, start a free trial!</textarea>
</div>
<div class="form-group col-sm-12">
<button id="btnSaveForms" align="center" type="button" class="btn btn-primary" onclick="openModal();">Save</button>
</div>
</form>
<div class="modal fade" id="saveForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">X</button>
</div>
<div class="modal-body">
<input type="text" id="formName" name="formName" required />
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-success" type="button" onclick="location.href='@Url.Action("SaveForm", "FormsCreator")'">Save</button>
<button data-dismiss="modal" class="btn btn-primary" type="button">Close</button>
</div>
</div>
</div>
</div>
<script>
function openModal() {
$("#saveForm").modal();
}
</script>
</body>
</html>
Everything works fine, but how can I get in my Controller SaveForm the value of mytextarea and formName from the view? So, I can save it into the database. BTW, I'm probably doing it in the wrong way, so please if there is a better way let me know.
Controler:
public ActionResult SaveFormPrintable(){
return View();
}
Thanks
$("#formId").submit()<form>, the hmtl element, andFormyour model. Rename your model and/or clarify your question.