Vote count:
0
I have the following MVC view to invite users to register to my site
@using (Html.BeginForm("Upload", "Tools", FormMethod.Post,
new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h2>Invite Users</h2>
<p class="text-info">@ViewBag.StatusMessage</p>
<div class="form-group">
@Html.LabelFor(m => m.EmailAddress, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.EmailAddress,
new { @class = "form-control", id = "email" })
@Html.ValidationMessageFor(m => m.EmailAddress)
</div>
</div>
<div class="form-group">
@Html.Label("Access To", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownList("Product", new SelectList(
new List<Object> {
new { Text = "DrGroup", Value = "DrGroup" },
new { Text = "UserCost", Value = "UserCost" },
new { Text = "All", Value = "All" }},
"Value",
"Text"),
new { @class = "form-control", id = "product" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="button" value="Invite User" class="btn btn-primary" />
</div>
</div>
}
This view has three tab pages, this is the first of three tabs. The ViewModel for this is view is
public class AdministratorViewModel
{
public string EmailAddress { get; set; }
public List<Download> Uploads { get; set; }
public List<ApplicationUser> UserList { get; set; }
}
I have the following JavaScript to pass the required fields back to the controller
<script>
$(function () {
$("input[type=button]").click(function () {
var data_email = $('#email').text();
var data_product = $('#product option:selected').text();
$.ajax({
url: 'Tools/SendInvite',
type: 'POST',
data: { email: data_email, product: data_product },
success: function (result) {
}
});
});
});
</script>
The controller method is
[HttpPost]
[AllowAnonymous]
public async Task<ActionResult> SendInvite(
string email, string product)
{
ApplicationUser user = null;
if (ModelState.IsValid)
{
user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user.IsAdmin != null && (bool)user.IsAdmin)
{
...
}
}
return RedirectToAction("Index", "Tools");
}
This method is fired, and product
is correct and contains the selected value. However, the email
is always empty.
Why is email always empty and how can I pass email to my controller?
Thanks for your time.
asked 49 secs ago
How to Get Value from TextBox in to Controller Method MVC
Aucun commentaire:
Enregistrer un commentaire