mvc4.0 html.actionlink comfired,MVC 4 Bootstrap Modal Edit \\ Detail

I think that I have a solution to your problem. To make your MVC application work as you want it to you should make some changes to the code you provided:

1. Add a div representing a modal for editing an item at the bottom of your layout page:

Notice that this modal is strictly connected to the controller action responsible for editing an EquipmentClass item.

2. Add a jQuery function to your custom javaScript:

function showModal(modalContainerId, modalBodyId, id) {

var url = $(modalContainerId).data('url');

$.get(url, { id: id }, function (data) {

$(modalBodyId).html(data);

$(modalContainerId).modal('show');

});

}

As you can see this function takes id as one of its parameters. In general its purpose is to replace the empty modal body with what we will put in a separate partial view and than display whole container as a modal page.

3. Put your modal div in a separate partial view, and call it Edit (has to be the same as your controller action name). You will have to change your Edit partial name to sth else, for example EditBody.

The Edit partial view should now look sth like this:

@model EquipmentClass

4. Change the controller action so that it returns the partial view created in the previous step:

public PartialViewResult Edit(int id)

{

return PartialView(equipmentclassRepository.Find(id));

}

5. Change the edit 'a' anchor so that it calls created jQuery function:

@model IEnumerable

....

@foreach (var item in Model)

{

@item.ClassId

@item.ClassName

}

This way each time an 'a' anchor with edit icon is clicked the showModal function (with related id being passed) is fired and a bootstrap modal with related data is displayed.

I'm sure there is a better way to do it, but this way worked for me just fine :)

Hope this helps you a bit :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值