page.aspx和(page.aspx.vb)背后的代码存在关系问题

Lef*_*nis 8 javascript vb.net ajax asp.net-mvc-4

我正在一个Web项目中工作,我决定从ASP.NET上交MVC 4。
在遇到许多问题之后,我可以处理该程序引发的事件。
在以前的ASPX.NET环境中,我双击了一个<asp:Button.../>控件,然后自动在后面的代码中看到了相关过程。
当然,每次我按下按钮时,程序都会执行此过程以及相关事件click
现在在MVC 4中,我遵循相同的过程,但是当我尝试按下按钮时,程序就永远不会执行该过程。
另一个例子是,当我有一个Label控件并且想使其可见或隐藏时,我使用

labelId.style.add(“Visibility”,”Hidden”) 或“可见”。

另一个是:

ValidationSummary.ValidationGroup
Run Code Online (Sandbox Code Playgroud)

现在在MVC中发生的情况相同,但是在使用控制器之前。
(使用控制器的原因是我想进入asp:buttonon_click程序,因为程序拒绝处理该事件。)
在控制器处理之后,对Label控件进行了评估,但它完全为空,使用空控件,我们可以什么也没做。
相同的情况ValidationSummary是空的,然后引发了一个错误,
直到现在
我使用继承时web.UI.Page程序都向我抛出此错误:

The view at '~ / Views / Home / Index.aspx' must derive from ViewPage
Run Code Online (Sandbox Code Playgroud)

因此,将继承更改为,ViewPage
并使用以下Javescript调用控制器:

 <script type="text/javascript">
function logSubmit() {
    var url = 'loginSubmit';
    $.ajax({
        type: 'GET',
        url: url,
        dataType: 'json',
    });
}
</script>
Run Code Online (Sandbox Code Playgroud)

从控制器,我在函数中使用以下指令:

   Public Function loginSubmit() As JsonResult
      Dim routes As New RouteCollection With {.RouteExistingFiles = True}
      Return Json(New With {Key Attributes.logSubmit.LoginButton_Click}, JsonRequestBehavior.AllowGet)
   End Function
Run Code Online (Sandbox Code Playgroud)

当发生这种情况时,我的任何控件都无法正常工作 page.aspx

在这个问题上有人可以协助我吗?

Ami*_*mir 2

正如评论中所说,Asp.net Web 表单和 Asp.Net MVC 是完全不同的概念。我知道你知道这一点。Asp.net Web 表单基于代码隐藏概念,而 Asp.Net MVC 具有基于路由的 URL,这意味着 URL 分为控制器和操作,而且它基于控制器而不是物理文件。在 Web 表单中,有服务器控件,但 Asp.Net MVC 遵循可自定义语法(默认为 Razor)。再次如评论所述,您无法在现有 ASPX Web 表单页面中使用 System.Web.Mvc.ViewPage 更改 System.Web.UI.Page。所以你需要使用剃刀语法来表达你的观点。根据你的问题,我可以建议如下。

    // View.    
@ModelType ViewModel   //Model you want to bind to the view.
     @Using Html.BeginForm("Login", "Account", New With {.ReturnUrl = ViewBag.ReturnUrl}, FormMethod.Post) // we pass action name as first parameter and controller name as third parameter.
                @Html.AntiForgeryToken()
                @<text>
                    @Html.ValidationSummary(True, "", New With {.class = "text-danger"})
                    <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"})
                            @Html.ValidationMessageFor(Function(m) m.Email, "", New With {.class = "text-danger"})
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(Function(m) m.Password, New With {.class = "col-md-2 control-label"})
                        <div class="col-md-10">
                            @Html.PasswordFor(Function(m) m.Password, New With {.class = "form-control"})
                            @Html.ValidationMessageFor(Function(m) m.Password, "", New With {.class = "text-danger"})
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-10">
                            <input type="submit" value="Log in" class="btn btn-default" />
                        </div>
                    </div>
                </text>
            End Using
Run Code Online (Sandbox Code Playgroud)

并在控制器中。

    Public Class AccountController
        Inherits Controller
        <HttpPost>
        <AllowAnonymous>
        <ValidateAntiForgeryToken>
        Public Async Function Login(model As LoginViewModel, returnUrl As String) As Task(Of ActionResult)
            If Not ModelState.IsValid Then
                Return View(model)
            End If
// Your code logic
            Dim result = Await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout := False)
            Select Case result
                Case SignInStatus.Success
                    Return RedirectToLocal(returnUrl)
                Case SignInStatus.LockedOut
                    Return View("Lockout")
                Case SignInStatus.RequiresVerification
                    Return RedirectToAction("SendCode", New With {
                        returnUrl,
                        model.RememberMe
                    })
                Case Else
                    ModelState.AddModelError("", "Invalid login attempt.") // Because of this we can show the validation summary on view using  @Html.ValidationSummary
                    Return View(model)
            End Select
        End Function
    End Class
Run Code Online (Sandbox Code Playgroud)

模型是。

//In your case model class is different.
Public Class LoginViewModel
    <Required>
    <Display(Name:="Email")>
    <EmailAddress>
    Public Property Email As String

    <Required>
    <DataType(DataType.Password)>
    <Display(Name:="Password")>
    Public Property Password As String

End Class
Run Code Online (Sandbox Code Playgroud)

我只是根据你的问题描述了我的理解处理你的问题的方法。