에 텍스트 상자에서 값을 가져 오는 방법을 나는 내 사이트이보기는 세 개의 탭 페이지가는 컨트롤러 방법 MVC
@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 = "Product1", Value = "Product1" },
new { Text = "Product2", Value = "Product2" },
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>
}
에 등록 사용자를 초대하려면 다음 MVC 뷰를 가지고,이 세 가지 탭의 첫 번째입니다. 이에 대한 뷰 모델은 뷰가 나는 다음과 같은 자바 스크립트가 컨트롤러에 다시 필수 필드를 통과해야
public class AdministratorViewModel
{
public string EmailAddress { get; set; }
public List<Download> Uploads { get; set; }
public List<ApplicationUser> UserList { get; set; }
}
<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>
컨트롤러 방법은
[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");
}
이 방법은 해고입니다입니다 , product
이 올 바르고 선택한 값이 들어 있습니다. 그러나 email
은 항상 비어 있습니다.
왜 전자 메일이 항상 비어 있으며 내 전자 메일을 내 컨트롤러로 전달할 수 있습니까?
감사합니다.
에 한번 교체하려면 $ ('# 메일') 텍스트() $와 :
또는 같은
var data_email = $('#email').val();
을. '#email'). val() – Zaphod