如何根据MVC中的下拉选择更改事件显示部分视图 [英] How to display a partial view based upon dropdown selection change event in MVC

查看:78
本文介绍了如何根据MVC中的下拉选择更改事件显示部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个交易明细屏幕,用户可以在其中选择他想要执行的交易类型。财务或非财务。在金融交易中有子类型,如现金提取,支票提款等。当用户输入所有详细信息并单击验证事务按钮时,某些规则将以存储过程的形式在后端运行,以根据用户选择的事务类型确定需要执行的验证类型,并且验证类型的视图正在获取在下一个屏幕上填充。验证类型可以是致电客户服务,要求签名验证等。 现在,在此页面上有一个下拉列表,其中包含所有验证类型。所以我想要做的是,当用户从下拉列表中选择任何验证类型时,需要显示该特定验证类型的视图。如何根据下拉选择更改事件显示该特定视图。我还需要在相同的下拉变化事件中填充模型。



我尝试了什么:



我写了一个jquery代码在下拉更改事件,但卡住如何使用jquery显示局部视图。此外,它在显示视图时显示模型null。我无法在下拉的更改事件中填写模型。

I have one transaction detail screen where user will select what type of transaction he wants to perform. Financial or non financial. In financial transaction there are sub types like cash withdrawal, check withdrawal and so on. When user enters all the details and clicked on validate transaction button, certain rules are run in the backend in the form of store procedure to determine what type of validation needs to perform based upon transaction type selected by the user and that validation type's view is getting populated on next screen. Validation type may be call customer care, ask for signature verification and so on.  Now on this page there a one dropdown list which contains all the validation type. So what I want to do is, when user select any validation type from dropdown list, view for that particular validation type is needs to display. How to display that particular view based upon dropdown selection change event. I also need go fill the model at same drop down change event.

What I have tried:

I have written a jquery code on drop down change event, but stuck how to display a partial view using jquery. Also it's showing model null while displaying a view. I am not able to fill the model at the change event of drop down.

推荐答案

引用:

但是如何使用jquery显示局部视图。

but stuck how to display a partial view using jquery.



这是一种方法:



首先,定义 div 元素。




Here's one way to do it:

First, define a div element.

<div id="divContainer"></div>





div 将作为 PartialView 的容器。



现在,在您的 jQuery 代码中,您可以加载 PartialView 到像这样的容器:





The div will serve as the container for your PartialView.

Now, in your jQuery code, you can load your PartialView to that container like this:


#divContainer)。load( @(Url.Action( YourPartialViewActionName YourControllerName ,new {id = TheIDParameterValueThatYouWantToPassInYourAction})));
("#divContainer").load("@(Url.Action("YourPartialViewActionName","YourControllerName", new { id = TheIDParameterValueThatYouWantToPassInYourAction }))");





或者,您可以使用jQuery .html()加载 PartialView 的功能就像这里演示的那样: https://www.c-sharpcorner.com/UploadFile/d551d3/how-to-load-partial-views-in -Asp-Net-mvc-using-jquery-ajax /



Alternatively, you can use the jQuery .html() function to load your PartialView just like what is demonstrated here: https://www.c-sharpcorner.com/UploadFile/d551d3/how-to-load-partial-views-in-Asp-Net-mvc-using-jquery-ajax/


基于ASp.NET mvc中的下拉信息重定向页面 - Stack Overflow [ ^ ]


这篇关于如何根据MVC中的下拉选择更改事件显示部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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