I am trying to post feedback on an object from a modal popup. No values on the popup are populated from server side.
<div class="modal fade" id="msg-editor">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Title of the form</h3>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="controls span10">
<label class="control-label" for="Title">Title and message</label>
<input type="text"
class="input-xlarge" id="Title" name="Title"
placeholder="Title of the message" />
<textarea class="input-xlarge" id="Message"
name="Message" rows="5" cols="9"
placeholder="Message"></textarea>
<label class="checkbox">
<input type="checkbox" value="option2" id="EmailSelf">
Send a copy of this message to yourself
</label>
</div>
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<a id="Submit" class="btn btn-primary" href="@Url.Action("AddDocumentMessage", "Invoice", new { param1 = $('#myFormSubmit').value, param2 = Model.Obj.Value1, param3 = Model.HashedValue })">Send</a>
</div>
</div>
The part that doesnt work is
param1 = $('#myFormSubmit').value.
How do I pass the client side value?
You can't...!
Because razor code is parsed and rendered in the server side, and in server, there is no jquery or any client code or data...
An alternative similar work can be like the following:
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<input type="button" value="Send" onclick="submit()" />
</div>
<script>
function submit() {
$.ajax({
url: @Url.Action("act", "con") + '?param1=' + $('#myFormSubmit').value +
'¶m2=' @Model.Obj.Value1 +
'¶m3=' + @Model.HashedValue,
type: 'POST',
// ... other ajax options ...
});
}
</script>
Then, in your action method you'll receive all params in string:
[HttpPost]
public ActionResult act(string param1, string param2, string param3)
{
ViewBag.Message = "Your contact page.";
return View();
}