0

I have a controller action like this:

public ActionResult Test(string par)
{
    Model myMod = new Model();
    myMod.Attribute = par;
    return View(myMod);
}

In the Test View I'd like to retrieve and print that attribute...
like this:

@model Project.Models.Model

@Html.DisplayFor(model => model.Attribute)

But by doing in that way I'm not able to retrieve the data from the action.

3
  • 2
    Using Model as the name of your ViewModel class is not a good choice. In Razor... @Model refers to the model passed to the view. It will became hard to understate... not sure it the intellisense will work as intended also. Commented Nov 20, 2013 at 17:03
  • View logic looks OK. Are you sure that par is set when you call the action? Commented Nov 21, 2013 at 9:22
  • I tried to write the url manually, i.e. localhost:8090/Home/Test/thisisthevalue and I suppose it opens a page, since the View is ok, with "thisisthevalue" displayed. Commented Nov 21, 2013 at 9:51

1 Answer 1

2

In your model, the property is called, Attribute, but in the view, you are referencing Attrubute:

@Html.DisplayFor(model => model.Attribute)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.