I have a model that I'm using to pass data from my view to my controller but I have some unbound from textboxes and dropdownlists. How can I pass that unbound data from my view back to my controller using ViewData or ViewBag....or something. Thanks!
相关问题
- Entity Framework throws exception - Network Relate
- Slow loading first page - ASP.NET MVC
- TextBoxFor decimal
- How to do an inline style with asp.net mvc 3 razor
- How to access the System.ComponentModel.DataAnnota
相关文章
- “Dynamic operations can only be performed in homog
- Change color of bars depending on value in Highcha
- How to get server path of physical path ?
- Breakpoint in ASP.NET MVC Razor view will not be h
- How to define function that returns html in asp.ne
- How to find the exceptions / errors when TryUpdate
- ASP.Net MVC 3: optgroup support in Html.DropDownLi
- A circular reference was detected while serializin
You can't pass data from the view to the controller using the ViewBag. The view (or at least the HTML generated from the view) can post data back to the controller using forms and the default binder would allow you to have objects provided as arguments to the controller's method.
If you want lots of data you can pass arrays, etc. using the correct naming guidelines and the default binder.
Other than that you would need additional data for us.
Can you give an example? It looks as if you're mixing up your terminology a bit. You don't generally pass data from a view to a controller except via a
POST/GET
. I'm going to assume that's what you meant. You can get any data into your controller's action method via a parameter with the same name or using aFormCollection
.In your view it might have something like:
MVC will automatically take the value of
yourUnboundTextBoxName
and insert that value into the parameter of the same name. Or you can use theFormCollection
and get the value from there.FormCollection["yourUnboundTextBoxName"]
You can send a model back to a controller in several methods. Here is just one of them. Since it seems like you only want a few items at a time sent back, possibly dynamically - this approach gives you a bit of control over what to send back and then uses a .ajax() request to do it.
Asp.Net MVC Passing an object from Url.Action in View to Controller
from the link above:
Note the ajax docs jQuery .ajax()