0

I am learning MVC and creating a project management site, and am stuck on a couple key ideas. I have a complex model, which includes a summary of the project, and a list of tasks

public class SummaryAndCategoriesViewModel
{
    public Project Summary { get; set; }
    public IEnumerable<task> Tasks { get; set; }
}

Inside the tasks, i've created an EditorTemplate, so that the user can switch each task state (from 'not started' -> 'completed'. for example)

In may main 'details' View, i have two partial views:

@{var categories = ViewData["AllCategories"] as List<Models.category>;}

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
    <div class="form-group">
    <div class="col-md-offset-2 col-md-10">
        <input type="submit" value="Save" class="btn btn-default" />
    </div>
</div>

<div class="form-horizontal">
    <hr />
    <div class="Summary">
    @Html.LabelFor(item => Model.Summary )
    @{Html.RenderPartial("_Summary", Model.Summary);}
        </div>
    <hr />
    <div class="tasks">
    @Html.LabelFor(item => Model.Tasks )
    @{Html.RenderPartial("_Task", Model.Tasks);}

        </div>
</div>
}

What I'd ideally like is that the 'summary' loads in the normal details view, which it does, while the 'tasks' loads in an edit mode, which i've done as well.

As of now, i'm stuck on two things:

1- I would like to be able to change only the 'summary' partial view to edit somewhow (modal popup could work too), and still perform httpPosts. 2- I would like the user to be able to change the 'tasks' partial view, and by clicking save, update the tasks in the database and refresh the 'tasks' partial. I've been reading up on the partials and renderpartials, but i'm a bit confused on which method I should be using, how to return the partial models to the HTTPPost, and how to switch the partial views.

Any guidance would be greately appreciated

chickenricekid
  • 390
  • 4
  • 19
  • 1
    [Partial vs RenderPartial](http://stackoverflow.com/questions/5248183/html-partial-vs-html-renderpartial-html-action-vs-html-renderaction). They both do essentially the same thing only in a different way –  Nov 10 '14 at 06:01
  • Is there some reason why you would not edit both the `Project` and its `Tasks` at the same time? –  Nov 10 '14 at 06:04
  • The reason is that the user would normally be updating just the task states. The project summary would usually stay constant, except for the few times where change of the summary items is needed – chickenricekid Nov 10 '14 at 06:06
  • 1
    In that case would it not be easier to have links on your details page to `Edit Project` and `Edit Tasks` that render different views (forms) and on post back, redirect back to the details page? –  Nov 10 '14 at 06:08
  • That is true.... Well in that case, lets say theoretically i wanted to go ahead with this anyways - how would this be done? – chickenricekid Nov 10 '14 at 06:10
  • 1
    Without knowing the full details, but probably 2 forms on the page, each with a button that uses ajax to post the form back to `SaveProject` and `SaveTask` methods. Since ajax stays on the same page, no need to _refresh the 'tasks' partial_ –  Nov 10 '14 at 06:19

0 Answers0