Note that there are some explanatory texts on larger screens.

plurals
  1. POView with two partialviews -- and two models
    primarykey
    data
    text
    <p>I am at a loss as to how to handle a situation in my first MVC 3 app (on razor).</p> <p>I have a page that displays a list of user-created goals. On that page the user clicks on a goal and is taken to a goals detail screen. This screen shows details of the goal (goal name, description, status). It also shows activities that lead to that goal and their details (activity name, status).</p> <p>I have goals in a 'goals' model and activities in an 'ilpActivity' model. The two are connected by the primary key of goals -> goalID</p> <p>I have two partialviews: _displayGoal and _activities Obviously _displayGoal needs the goals model while _activities needs the ilpActivity model.</p> <p>Each of these use ajax calls to forms that allow editing (and also creation for activities).</p> <p>On my main view, goalDetails, I reference the goals model.</p> <p>My problem - I can't use an @Html.Partial call to _activities because it uses a different model. I thought I cleared that hurdle by using RenderAction - however it works in firefox but caches in IE. That is, changes I make are not seen unless I refresh my screen.</p> <p>I hope that makes sense... basically I need to call two partialviews that use two models. I've read quite a bit but have struggled to make things work. </p> <p>Do I disable caching? - I tried this but duration = 0 throws an error</p> <p>Do I need a model that can call both models? - I'm unsure what this looks like in the model and in the controller. I'm pulling details on 1 goal while pulling a List&lt;> of activities.</p> <p>I'm confused and welcome any recommendations. Here's some code:</p> <p>My Model:</p> <pre><code>namespace ILP.Models { public class goalsModel { #region services public interface IGoalsService { goals GetGoal(int id); List&lt;ilpActivity&gt; GetGoalActivities(int id); } public class AssetService : IGoalsService { private goalsDataClassesDataContext qDB; /// &lt;summary&gt; /// reference the data context /// &lt;/summary&gt; public AssetService() { qDB = new goalsDataClassesDataContext(); } #region IGoalsService Members public goals GetGoal(int id) { return qDB.goals.Single(g =&gt; g.goalID == id); } public List&lt;ilpActivity&gt; GetGoalActivities (int id) { //return all activities for goal 'id' return qDB.ilpActivities.Where(g =&gt; g.goalID == id). OrderBy(g =&gt; g.activityName) .ToList(); } </code></pre> <p>My Controller:</p> <pre><code> [Authorize] public ActionResult ViewGoal(int goalID) { goals goal; try { goal = qService.GetGoal(goalID); } catch { goal = new goals(); } return View(goal); } [Authorize] public ActionResult _Activities(int goalID) { List&lt;ilpActivity&gt; activity; try { activity = qService.GetGoalActivities(goalID); } catch { throw; } return PartialView(activity); } </code></pre> <p>And then my view:</p> <pre><code>@model ILP.Models.goals &lt;div id="thisGoal"&gt; @*@{ Html.RenderPartial("_ActiveGoals", Model);}*@ @Html.Partial("_EditDisplay", Model) &lt;/div&gt; &lt;br /&gt; &lt;div id="activities"&gt; @{Html.RenderAction("_Activities", "Home", Model.goalID);} @*@Html.Partial("_Activities",Model)*@ &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload