如何将模型与局部视图绑定 [英] How to bind the model with partial view

查看:83
本文介绍了如何将模型与局部视图绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i have the model with a list of multiple files.User can update the list of files. If I display the list as partial view I have no problem to update the partial view using Ajax call without reloading page,unfortunately there is no binding with model.
 @Html.Partial("pDisplayFilesBeforeSave", Model.FilesList)

I tried to use @Html.EditorFor(Function(Model) Model.FilesList()). And there is no issues with the binding, But  I don not know how to refresh the  @Html.EditorFor after user removed the file. My jscript function below>
function CancelUpload(id)
    {
    
        if (confirm('Are you sure you want to cancel upload for this file?')) {
            $.ajax({
                url: '@Url.Action("RemoveFile", "FileUpload")',
                type: "Get",
                data: { ID: id },
                dataType: "html",
                success: function (partialView) {
                $('#div_to_loadFiels_PartialView').html(partialView);
                },
            });
        }
    }





我的尝试:





What I have tried:

I tried everything I could think of. I have posted the question on Expert-Exchange. no luck

推荐答案

.ajax({
url:'@ Url.Action(RemoveFile,FileUpload) ',
类型:获取,
数据:{ID:id},
dataType:html,
成功:函数(partialView){
.ajax({ url: '@Url.Action("RemoveFile", "FileUpload")', type: "Get", data: { ID: id }, dataType: "html", success: function (partialView) {


('#div_to_loadFiels_PartialView')。html(partialView);
},
});
}
}
('#div_to_loadFiels_PartialView').html(partialView); }, }); } }





我的尝试:





What I have tried:

I tried everything I could think of. I have posted the question on Expert-Exchange. no luck


这篇关于如何将模型与局部视图绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆