我们如何将数据从部分视图传递到父视图控制器操作方法 [英] How can we Pass Data From Partial Views To Parent View Controller Action methods

查看:58
本文介绍了我们如何将数据从部分视图传递到父视图控制器操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何将数据从部分视图传递到父视图控制器操作方法

How can we Pass Data From Partial Views To Parent View Controller Action methods

推荐答案

在.NET MVC中,您有几个传递值的选项。当转到控制器到控制器时,您可以将TempData []集合用于单跳。只有控制器才能访问此集合,它主要用于操作重定向。



如果您需要保留数据以供在给定会话中使用,您可以使用Session []集合为每个会话提供每个用户的应用程序状态。所有视图和控制器都可以访问此集合。



您可以使用ViewData []集合将元素传递到视图中并将它们分配给变量容器(例如JavaScript变量) )主视图已知。然后,您可以使用JavaScript在客户端进行任何更改。
In .NET MVC you have a couple of options to pass values around. when going controller-to-controller, you can use the TempData[] collection for single hops. Only controllers can access this collection, and it is primarily useful for action redirects.

If you need to persist data for a use in a given session, you can use the Session[] collection to provide an application state per user, per session. All views and controllers can access this collection.

You can use the ViewData[] collection to pass elements into the view and assign them to variable containers (such as JavaScript variables) that are known by the Master view. You can then make any changes on the client side using JavaScript.


这篇关于我们如何将数据从部分视图传递到父视图控制器操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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