如何从文本框中检索值

时间:2015-12-22 09:37:51

标签: asp.net asp.net-mvc vb.net asp.net-mvc-5

您好我正在尝试从文本框(电子邮件)中检索值,但是我不知道如何这样做,因为我是新的ASP.NET MVC5。

目前我有这个代码要求用户输入他们的电子邮件。

<div class="form-group">
    @Html.LabelFor(Function(m) m.Email, New With {.class = "col-md-2 control-label"})
    <div class="col-md-10">
        @Html.TextBoxFor(Function(m) m.Email, New With {.class = "form-control"})
    </div>
</div>

以下是创建弹出窗口以获取用户对帐户创建的确认的方法。

    <div class="col-md-offset-2 col-md-10">
        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Submit</button>
    </div>

//下面的代码是#myModel     

    <!-- Modal content-->
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Confirmation</h4>
        </div>
        <div class="modal-body">
            <p>Are you sure you want to Register an account</p> // want to add the email that was input in the textbox earlier on**

        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-default" value="Register"> Submit </button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>

</div>

注册控制器在

之下
Public Function Register() As ActionResult
    Return View()
End Function

<HttpPost>
<AllowAnonymous>
<ValidateAntiForgeryToken>

Public Async Function Register(model As RegisterViewModel) As Task(Of ActionResult)
    If ModelState.IsValid Then
        Dim user = New ApplicationUser() With {
            .UserName = model.Email,
            .Email = model.Email
        }
        Dim result = Await UserManager.CreateAsync(user, model.Password)
        If result.Succeeded Then
            Await SignInManager.SignInAsync(user, isPersistent:=False, rememberBrowser:=False)
            Return RedirectToAction("Index", "Home")
        End If
        AddErrors(result)
    End If

    Return View(model)
End Function

1 个答案:

答案 0 :(得分:0)

<div class="form-group">
  @Html.LabelFor(Function(m) m.Email, New With {.class = "col-md-2 control-label"})
   <div class="col-md-10">
    @Html.TextBoxFor(Function(m) m.Email,, new { id = "EmailID", @clas= "orm-control", placeholder = "EmailID" })
   </div>
</div>

在javascript上你可以得到像这样的值

 var meetingRoom = $('#meetingRoom').val();