views:

64

answers:

2

Hello,

I am wondering how I can pass a model back to an action so that I can continue to work on the data but in a different action based on the button's pressed

To send it back, I specify the Control, Action and use the new { dom = Model } to specify the parameter.

dom is a List (so a list of domain objects. My model passed in is an IQuerable. When I make dom an IQuerable, I still receive nothing back from the view. here is the snippet, using telerik controls

VIEW

<% Html.Telerik().Grid(Model).Name("Domains")
        .DataKeys(dataKeys => dataKeys.Add(c => c.DomainId)).DataKeys(dataKeys => dataKeys.Add(c => c.Timestamp))
        .Columns(columns =>
            {
                columns.Template(o =>
                 {  %>
        <%= Html.Encode(Html.OutputAction(ViewData["PerformActions"] as List<string>))%>
        <%
            }).Title("Action");
                columns.Bound(o => o.DomainId);
                columns.Bound(o => o.Name);
                columns.Bound(o => o.SiteId);
                columns.Bound(o => o.ScrubAndRedirect);
                columns.Bound(o => o.ReportingSiteId);
                columns.Bound(o => o.TrafficCopClass);
                columns.Bound(o => o.SiteName);
                columns.Bound(o => o.FeedType);
                columns.Bound(o => o.Active);
            }).Pageable().Sortable().Filterable().DataBinding(db => db.Server().Select("Domains", "Preview", new { doms = Model })).Render();%>


*ACTION*

 public ActionResult Preview(List<Domain> doms)
        {
            return View("Preview", doms.AsQueryable<Domain>());
        }

Thanks

A: 

I think what you want to do is just have your Preview and Commit actions both take in List doms. If preview doesn't post it, you may need to have an EditorForModel somewhere (even if it's hidden). In other words, your edit view posts to the preview action, which shows a view, and then THAT page should post the data to your commit action. I believe that would do it. Hope that helps..

Robert Seder
How would I go about doing this? Sorry I am very new to MVC and C# so I haven't been using them for very long.
DMan
Just more of the same of what you already have. Have a public ActionResult Preview(List<Domain> doms) {} then a public ActionResult Commit(List<Domain> doms) {}, if you use a Html helper on the the page (like EditorForModel), the data structure/DTO will be "POST"ed back to the Commit action. Does that help?
Robert Seder
Thank you for the help,I figured out how to do it, I instead of trying to pass back the whole list, I just recreated it from the file path (so i passed back the file path to the preview function and had it reconstruct the list). This method surprisingly enough didn't add to much overhead to the program, and that's why I initially didn't want to do it that way, as I figured if I remade the list every time it would be taxing on the system. Thanks again
DMan
A: 

In general in MVC, you do not pass large lists of DOM objects back to the server to "re-construct" a list of entity or domain objects. When values are posted to a Controller action, they are almost always from an HTML form. Behind the scenes, MVC is extracting the values from the POST via the

Request.Forms["fieldName"]

And then trying to auto-map the values to params in your ActionMethod.

If I understand your scenario, the most common practice would be to submit or pass a KEY (or some identifier) to the Controller when an action is fired and then use that to grab the necessary domain objects (either from a cache, from a database, from disk, etc.). If scalability is a concern, a good caching strategy can help avoid costly I/O operations.

Hope that helps.

Todd