0

I have partial view for deleting user. I use bootstrap modal popup for this action.

So my codes are as follows.

Index.chtml

    @*Inside foreach loop*@
   <div class="modal hide fade" id="Delete_@index">
         @Html.Partial("_DeleteUser", user)
   </div>

_DeleteUser

@model Classes.User

<div class="modal-header">
   <button type="button" class="close" data-dismiss="modal">×</button>
   <h3>İstifadəçinin məlumatları</h3>
</div>
   @using (Html.BeginForm("DeleteUser", "Admin", FormMethod.Post))
   {
       Html.HiddenFor(user => user.UserId);
       Html.AntiForgeryToken();
       <div class="modal-body">
           <strong>Bu istifadəçini silmək istədiyinizdən əminsiniz...?</strong>
       </div>
       <div class="modal-footer">
           <a href="#" class="btn" data-dismiss="modal">Close</a>
           <button class="btn btn-danger"><i class="icon-trash icon-white"></i>Save Changes</button>
      </div>
   }

And my HttpPost method action:

    [HttpPost]
    public ActionResult DeleteUser(User user)
    {
        userRepository.DeleteById(user.UserId);
        return View("User");
    }

After this scenario I get {00000000-0000-0000-0000-000000000000} type Guid value for User.UserId. Perhaps its has very easy solution, but I can not find an hour. Please help me.

Not: I use

1)Html.HiddenFor(user => user.UserId);
2)<input type="hidden" value="@Model.UserId" id="UserId"/>

but still not work.

Solution: *It works when I move hidden inside model-body div, why it happend I don't know)), thanks a lot to everyone*

4

1 回答 1

1

在您的局部视图中查看源代码。不久前我有类似的设置和结果。发现我必须以不同的方式做我的隐藏领域。使用

<input type="hidden" value="@Model.UserId"> 

在 html.hiddenfor 为空的地方有正确的 id。

于 2013-09-18T16:45:29.560 回答