Doubt with Tipada View?

0

I have the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PostGetModel.Models;

namespace PostGetModel.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            var pessoa = new Pessoa
                {
                    PessoaId = 1,
                    Nome = "teste teste",
                    twitter = "@teste"

                };

            return View(pessoa);
        }

    }
}

no Index:

The code does not complete in this part where I add the: PostGetModel what could be wrong?

@Model PostGetModel.Models.Pessoa;
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>model.PessoaId</p>

    
asked by anonymous 30.09.2014 / 19:49

1 answer

1

ItaSouza,

In this part of the code

<p>model.PessoaId</p>

To access your model, you would need to do the following:

<p>@Model.PessoaId</p>

This is because by putting an element without the "@" inside an HTML tag, Razor interprets this as an HTML code, not a C # code.

If the name of the View is index, as you indicated, it must have the same name as your Action, in this case, Index, inside the Home folder. However, if the exception you raise is in View, then you are successfully accessing the page.

As indicated also by Leandro, the directive that indicates which ViewModel of your view should always be low, whereas to access the Model attribute of your view, this must always be in uppercase.

    
30.09.2014 / 19:59