views:

57

answers:

2

I have a web application containing both asp.net web forms and mvc views but run into issues with strongly typed models in the view.

This is the page directive from the view:

<%@ Page Inherits="System.Web.Mvc.ViewPage<Survey.Models.SurveyResponse>" Language="C#" MasterPageFile="~/Views/Shared/ExternalSurvey.Master" %>

but within the view i have no access to the Model property.

In the controller i have

return (new Survey.Models.SurveyResponse());

Why do i not have access to the Model property within the view?

+1  A: 

To get a Strongly Typed Model in the view, you need to use the ViewModel pattern outlined here.

George Stocker
I tried this but doesn't seem to work, my example is very similar to the dinner's index that uses PaginatedList as the model
Jon
Can you post the code? I've used this method and am able to get strongly typed models in my views, so I'd need to see the code to see what you might be missing.
George Stocker
A: 

I'm guessing, from the nature of your return statement in the question, that SurveyResponse inherits from something--perhaps ViewResponse. This isn't quite the way to go about this. Rather, you need to create a data object that encapsulates the data you wish to view, then pass it through a view response:

MyDataObject obj = new MyDataObject();
//set some properties, etc
return View(MyDataObject);

Then you can access MyDataObject in a strongly typed manner via the Model property.

Wyatt Barnett