Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
Posted
Updated 25-Jul-17 0:51am
v2
Comments
What have you tried and where is the problem?
Member 9367927 8-Jul-15 4:39am    
657869768

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:

C#
public class CreditCardInfo
{
    public string CardNumber { get; set; }
    public string Span { get; set; }
    public int ExpiryMonth { get; set; }
 }


Action Method :

C#
//persist data for next request
TempData["CreditCardInfo"] = creditCardInfo;



Your 2nd View :

C#
@{
      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
 
Share this answer
 
v2
Comments
Dot Net Beginer 4-Dec-15 2:01am    
I am also facing same problem from "view to view" not from ActionMethod to view
This solution works for me. thanks for your information.
 
Share this answer
 
Comments
CHill60 12-Jul-16 10:54am    
Please do not post comments as solutions to old questions. Next to each post is a "Have a question or comment?" link which allows to comment (like this)
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900