将数据从一个视图传递到mvc3中的另一个视图 [英] pass data from one view to other view in mvc3

查看:68
本文介绍了将数据从一个视图传递到mvc3中的另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何将数据从一个视图传递到mvc3


how to pass data from one view to controller in mvc3

推荐答案


您好,

mvc中有多种方法可以将数据从视图传递到控制器.这取决于您的应用程序的故事,这意味着您要在控制器,POST或GET方法中传递数据的位置.

GET 方法中,您可以通过使用Java脚本或jqury调用action来传递值.

我将向您说明如何通过在" FormCollection "中使用控制器将视图中的值传递给POST方法.

FormCollection是通用集合,其中值存储在键-值"对中.但是您只能通过POST方法才能从中获得价值.

请参阅以下代码.

在视图中
Hello,

There are number ways available in mvc to pass the data from view to controller. it depends on what''s the story on your application means where you want to pass the data in controller ,POST or In GET Method.

In GET Method you can pass the value by calling action using java script or jqury.

I will explain you how to pass value from view to POST Method in controller by using in "FormCollection"

FormCollection is generic collection in which value store in "key-Value" pair. but you can get value from this only on POST Method.

refer following code stuff.

In View
@using(Html.BeginForm("actionName","ControllerName",FormMethod.Post))
{
      @Html.Editor("Key","Value")
} 


在控制器中


In Controller

[HttpPost]
public ActionResult ActionName(FormCollection coll)
{
   string value = coll["Key"];
}



这样,您还可以将值从视图传递到控制器 POST 方法.



In this way also you can pass the value from view to controller POST Method.


这篇关于将数据从一个视图传递到mvc3中的另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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