0

I have a controller that makes a GET request and returns JSON. I want to then bind those values to the ViewModel that returns to the View.

[HTTPGET]
public async Task<IActionResult> Name(string id) {
  ViewModel model = new ViewModel();
  var name = await GetNameFromBYId(id);

  name = model.Name;//HOW Do I do This?

}
1
  • 2
    model.Name=name; is the correct syntax Commented Mar 28, 2017 at 17:03

1 Answer 1

0
[HTTPGET]
public async Task<IActionResult> Name(string id) {
  ViewModel model = new ViewModel();
  var name = await GetNameFromBYId(id);

  model.Name = name; // Right code

}

This code

model.Name = name;

only works, if you've created the right Viewmodel before. That means you have defined the right Properties in it. In your example you need to define a "Name" property before in your model, to pass data trough it.

If you have Problems to understand how the MVVM - Pattern works you can search for a simple tutorial like this. Click and read (!), to learn how you make and use ViewModels. Enjoy!

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.