如何渲染MVC中组合框选择的局部视图? [英] how do I render a partial view on combobox selection in MVC ?

查看:125
本文介绍了如何渲染MVC中组合框选择的局部视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC中有一个包含组合框的视图。关于这个组合框的选择更改,我想绘制一个动态的html表。对我来说最好的方法是使用局部视图。是否可以在每次更改组合框所选项目时呈现局部视图?

I have a view in MVC which contains a combobox. On selection change of this combobox I want to draw a dynamic html table . The best approach for me is to use a partial view. is that possible to render the partial view every time the combobox selected item is changed??

推荐答案

您可以使用AJAX调用加载更改事件的局部视图下拉列表。代码将是这样的: -



You can use an AJAX call to load a partial view on the change event of Dropdown. The code will be something like that:-


.ajax({
url:' @ Url.Action(ActionName)'
类型: ' GET'
cache: false
data:{id:someID}
})。done( function (result){
.ajax({ url: '@Url.Action("ActionName")', type: 'GET', cache: false, data: { id: someID } }).done(function(result) {


' #SomeDiv')。html(result);
}) ;
('#SomeDiv').html(result); });





以上代码: -



ActionName 将是返回部分视图的某个Action的名称。

someID 将是您从Dropdown的更改事件中获得的ID。

SomeDiv 将是您网页上某些DIV的ID视图将获得渲染。



In above code:-

ActionName will be the name of some Action which is returning a Partial View.
someID will be the ID which you get from the change event of Dropdown.
SomeDiv will be the ID of some DIV on your page where partial view will get render.


这篇关于如何渲染MVC中组合框选择的局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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