如何在asp.net mvc razor中将值从一个视图传递到另一个视图? [英] How to pass value from one view to another view in asp.net mvc razor?
问题描述
如何在asp.net mvc razor中将值从一个视图传递到另一个视图?
在第一个视图中(从第一个视图插入数据,它将在另一个视图中显示)
Id:___ 1001 _____(文本框)
名称:__ abc _____(文本框)
保存按钮
------------------ -----------
在第二个视图中
Id:1001
名称:abc
谢谢
Gyanendra
您可以使用 TempData 。
注意:以下示例已从我的博客中提取文章。请根据您的情况进行更改。
型号:
<前lang =cs> < span class =code-keyword> public class CreditCardInfo
{
public string CardNumber { get ; set ; }
public string Span { get 跨度>; set ; }
public int ExpiryMonth { get 跨度>; set ; }
}
行动方法:
// 为下次请求保留数据
TempData [ CreditCardInfo] = creditCardInfo;
您的第二视图:
@ {
if (TempData [ CreditCardInfo]!= null )
{
var creditCardInfo = TempData [ CreditCardInfo] as CreditCardInfo;
}
}
查看我的博客文章的更多信息:
如何正确使用Asp.Net MVC TempData
此解决方案适合我。感谢您的信息。
在第一个视图中显示数据时,该详细信息将在第一个模型中。只是将该模型传递给第二个视图。这都是
Hi,
How to pass value from one view to another view in asp.net mvc razor?
In 1st View(inserting data from 1st view it will show in another view)
Id : ___1001____ (textbox)
Name : __abc_____ (textbox)
save button
-----------------------------
In 2nd view
Id :1001
Name:abc
Thanks
Gyanendra
You can use TempData for that.
Note:Below example has been extracted from my Blog Article.So please Change it according to your scenario.
Model:
public class CreditCardInfo { public string CardNumber { get; set; } public string Span { get; set; } public int ExpiryMonth { get; set; } }
Action Method :
//persist data for next request TempData["CreditCardInfo"] = creditCardInfo;
Your 2nd View :
@{ if (TempData["CreditCardInfo"] != null) { var creditCardInfo = TempData["CreditCardInfo"] as CreditCardInfo; } }
Check for more info on My Blog Article :
How to use Asp.Net MVC TempData Properly
This solution works for me. thanks for your information.
When you displaying the data in 1st view, that details will be in 1st model. just pass that model to the 2nd view. that's all
这篇关于如何在asp.net mvc razor中将值从一个视图传递到另一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!