0

我的登录是部分视图。我将包含tbl_profile 的某些字段的模型传递给部分视图并填充它,然后我将填充的模型传递给 [HttpPost] 部分的 actionresult 并且......但现在我在 [HttpGet] 部分遇到了麻烦。我在这行 cod " * @Html.Action("LogOn","Account")" *. 我的代码:

     [HttpGet]
    public ActionResult LogOn(string returnUrl)
    {

         using (var db = new MyContext())
        {

           var  AllFeatureToLog = db.tbl_profile.Select(u => new UsersClass.LogOn { username = u.username, password_User = u.password_User }).ToList();

            return PartialView(AllFeatureToLog);
        }
    }

班级:

   public class UsersClass
   {
    public class LogOn
    {
        public string username { get; set; }
        public string password_User { get; set; }
    }
   }

登录.cshtml:

    @model MyProject.Models.UsersClass.LogOn     
    @using (Html.BeginForm())
     {
     @Html.AntiForgeryToken()
   <form class="signin-form">

     @Html.TextBoxFor(m => m.username, new { @id = "username", @class = "input-block-       level", @placeholder = "* enter username" })
     @Html.TextBoxFor(m => m.password_User, new { @id = "password", @class = "input-block-level", @placeholder = "* enter pass" })
     @Html.ValidationMessage("LoginError")

<label class="checkbox">
    <input type="checkbox">remember me</label>
<button class="btn btn-medium btn-general input-block-level" type="submit">   enter</button>
 </form>
 }

错误:

     Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'
4

2 回答 2

0

改用这个::

@{ Html.RenderAction("LogOn","Account"); }

这将解决您的问题。

于 2013-08-15T16:00:50.657 回答
0

您发送列表:

var  AllFeatureToLog = db.tbl_profile.Select(u => new UsersClass.LogOn { username = u.username, password_User = u.password_User }).ToList();
return PartialView(AllFeatureToLog);

但是您的 View 只期望一个模型:

@model MyProject.Models.UsersClass.LogOn

更改:发送时您的 ActionResult :var AllFeatureToLog = db.tbl_profile.Select(u => new UsersClass.LogOn { username = u.username, password_User = u.password_User }).Fist();

或查看获取列表:@model IENumerable<MyProject.Models.UsersClass.LogOn>

于 2013-08-15T17:01:18.580 回答