Question

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*

Was it helpful?

Solution

Look at the source on your partial view. I had a similar setup and result a while ago. Found that I had to do my hidden field differently. Using

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

had the correct id where html.hiddenfor was empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top