How to send data from controller to view page in asp.net MVC?
How to send data from controller to view page in asp.net MVC? also define how many way to send data from controller to view?
The information provided here is part of Export Import Training online After the exploration of information technology, the world is on our finger tips to get any piece of information. However when I went through different subjects on the web, I realized, like every thing in society, internet also carries the good and the bad. I was surprised to note that, I could not find any good quality free tutorial program to enter in a good business especially in
roj ldee
01-Sep-2022Like someone said your names are colliding. If you use Fiddler you'll see what you post looks like FirstName='asdf' LastName='asdf' FirstName='123' LastName='123' , which property goes with which item in the list<t> ? MVC can't figure it out either and will be empty at the break point.
If your html names were indexed something like <input name='collection[0].FirstName.. and name='collection[1].FirstName.. you should actually get the correct values.
roj ldee
01-Sep-2022Like someone said your names are colliding. If you use Fiddler you'll see what you post looks like FirstName='asdf' LastName='asdf' FirstName='123' LastName='123' , which property goes with which item in the list<t> ? MVC can't figure it out either and will be empty at the break point.
If your html names were indexed something like <input name='collection[0].FirstName.. and name='collection[1].FirstName.. you should actually get the correct values.
Maybe it's too early but I'm having trouble understanding what you're trying to do overall. I'd recommend not sending the whole list<t> back to the controller. Wouldn't it be better to create a separate view for editing the items? Or even putting that edit view in a partial to display in a modal?
Steilla Mitchel
11-Mar-2022Pass Data Controller to View in asp.net MVC:
We have three ways to send data from controller to view in asp.net mvc application. Those are
1- TempData
2- ViewBag
3- ViewData
1- TempData:
Temp data is used to send data from controller to controller or controller to view in asp.net mvc. it has short life and it required typecasting. It is used to pass data from current active page to next page. TempData is a dictionary object, it is derived from TempDataDictionary class.
Exp-
Here is controller page to return a message to view using TempData,
Here we create a view page 'Index.cshtml' to show the message
2- ViewBag :
ViewBag is used to pass data from controller to view in asp.net mvc. It does not need to typecasting and it contains null value when it redirection occures.
Exp-
Create model page to send data to view
Create View to execute messate
3- ViewData:
ViewData is also like TempData. It also derived from ViewDataDictionary and it also need to typecasting.
create model page to return message to view using ViewData
Now create View page to show message of ViewData