Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn partial view if action is ajax or child action universally
    text
    copied!<p>Hi guys I have burned up google trying to construct some kind of class that will determine <strong>UNIVERSALLY</strong> if it is a AJAX call or child action or action so that my controllers can determine whether to return a partial view or a full view. So far I havent had much luck. At the moment I am using the following code to achieve this</p> <pre><code> if (Request.IsAjaxRequest() || ControllerContext.IsChildAction) { return PartialView(); } return View(); </code></pre> <p>The problem is you have to do this in every action in a controller and every Condition you encounter but I am sure there is a way to achieve this via a helper but cant figure out how. Can you please point me to any links/example code to achieve this. </p> <p><strong>Edit:</strong> </p> <p>@Aron I have posted a piece of code as whole controller would be too long. But you can see my predicament. The return contains a View and a Object/Model "k".</p> <pre><code>public ActionResult _Details_Message(int id = 0, int CId = 0) { ViewBag.MrnSortParm = CId; if (id != 0) { var k = mrn.MRNS.Where(u =&gt; u.Id == id).SingleOrDefault(); if (k.To == User.Identity.Name) { if (k.Type == 0) // message { k.Read = true; mrn.Entry(k).State = EntityState.Modified; mrn.SaveChanges(); } return PartialView("_Details_Message", k);//replace the above code here } if (k.From == User.Identity.Name) { return PartialView("_Sent", k); //replace the above code here } } var m = new message(); m.CourierId = CId; return PartialView("_Create_Message", m); //replace the above code here } </code></pre> <p><strong>Edit 2</strong> I have found an answer it isn't an helper function but a modification in the view. The link is <a href="https://stackoverflow.com/questions/5318385/mvc-3-how-to-render-a-view-without-its-layout-page">here</a> . Can mark my own question as duplicate :(</p>
 

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