29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

In the Index action method, I pass a pair of string arrays to the view via the view bag and set the model object to be a<br />

string. I added a view called Index.cshtml to the Views/Home folder. You can see the contents of the view file in<br />

Listing 21-2. This is a strongly typed view (where the model type is string) and I have not used a layout.<br />

Listing 21-2. The Contents of the Index.cshtml File<br />

@model string<br />

@{<br />

}<br />

Layout = null;<br />

<br />

<br />

<br />

<br />

Index<br />

<br />

<br />

<br />

Here are the fruits:<br />

@foreach (string str in (string[])ViewBag.Fruits) {<br />

@str <br />

}<br />

<br />

<br />

Here are the cities:<br />

@foreach (string str in (string[])ViewBag.Cities) {<br />

@str <br />

}<br />

<br />

<br />

Here is the message:<br />

@Model<br />

<br />

<br />

<br />

Setting the Start URL<br />

I want Visual Studio to start with the root URL for the application rather than guess the URL based on the file that is being edited.<br />

Select HelperMethods Properties from the Visual Studio Project menu, switch to the Web tab and check the<br />

Specific Page option in the Start Action section. You don’t have to provide a value. Just checking the option is<br />

enough.<br />

Testing the Example Application<br />

You can see how the view is rendered by starting the application. The default routing configuration added to the project by Visual<br />

Studio will map the root URL requested automatically by the browser to the Index action on the Home controller, as shown in<br />

Figure 21-1.<br />

554

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!