Toolroom Tech Blog

Devlopers Digest

Returning Templates after AJAX Request in MVC 3

How to return a DisplayTemplate or EditorTemplate in a partial response after AJAX calls in ASP.net MVC 3.

Ever had the need to return a DisplayTemplate or EditorTemplate within a Response after an AJAX call? Altough it is not very nice, the easiest way seems to be this ... and it may save lots of time: just access the view directly by its filename.

public PartialViewResult GetNew()
{
	return PartialView(
		"~/Views/Receipe/EditorTemplates/IngredientModel.cshtml", 
		new IngredientModel { Id = Guid.Empty }
	);
}
Loading