Like 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.
Like 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?
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-
// Gets or sets the dictionary for temporary data. // Returns:
// The dictionary for temporary data.
public TempDataDictionary TempData { get; set; }
Here is controller page to return a message to view using TempData,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mindstick.Controllers
{
public class DemoController : Controller
{
public ActionResult Index()
{
TempData['Demo'] = 'hello Tempdata';
return View();
}
}
}
Here we create a view page 'Index.cshtml' to show the message
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-
// Gets the dynamic view. // Returns: // The dynamic view. [Dynamic]
public dynamic ViewBag { get; }
Create model page to send data to view
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mindstick.Controllers
{
public class DemoController : Controller
{
public ActionResult Index()
{
ViewBag.msg = 'hello ViewBag';
return View();
}
}
}
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mindstick.Controllers
{
public class DemoController : Controller
{
public ActionResult Index()
{
ViewData['msg'] = 'hello Viewdata';
return View();
}
}
}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Like 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.
Like 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?
Pass 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
@{ViewBag.Title = 'Index';
}
<h2>Index</h2>
@TempData['Demo']
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
@{ViewBag.Title = 'Index';
}
<h2>Index</h2>
@ViewBag.msg
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
@{
ViewBag.Title = 'Index';
}
<h2>Index</h2>
@ViewData['msg']