2

this should be straight forward, just cant figure out why it's not working.

I receive data in this format from Web API 2 (captured from Chrome's debugger):

enter image description here

AngularJS code to render the results
(vm.reportParameters contains that structure on the screenshot with 2 nodes):

<form>
    <div ng-repeat="param in vm.reportParameters" class="form-group">
        <label>Name</label>
        <input type="text" class="form-control" value="{{param.Name}}" />
    </div>
</form>

The output (missing value of Name property, should display "Country"):

enter image description here

Any idea what I am missing here? Why the value is not shown?

// GET api/reports/5
// This action retrieves parameters of selected report by reportId
[ResponseType(typeof(ParametersModel))]
public IHttpActionResult Get(string reportId)
{
    try
    {
        var manager = new ReportsManager();
        var model = manager.GetReportParameters(reportId);
        if (model == null || model.Parameters == null || model.Parameters.Count == 0)
        {
            return NotFound();
        }
        return Ok<ParametersModel>(model);
    }
    catch (Exception ex)
    {
        return InternalServerError(ex);
    }
}

Thanks.

UPDATE

This garbage-alike data has this weird format with all these k__XXXXX things because I had various attributes applied to the model for XML Deserialization (in C# code). After I removed all these Serialization attributes, the model became normal and clean as expected. Go guess :)

monstro
  • 6,254
  • 10
  • 65
  • 111
  • yep, that's how Web API 2 returns data (the response object), that's why I am asking :) – monstro Jan 19 '17 at 20:30
  • 1
    Wild...that's not how my collections are returned from WebAPI 2. What return type are you using on the controller method? Are you not using `IHttpActionResult`? – Lex Jan 19 '17 at 20:37
  • Seeing your endpoint will probably be helpful. I've never seen that much cruft in my response before. Usually it's just `{property: value, property: value}`, standard json. – Yatrix Jan 19 '17 at 20:39
  • @Lex, I added code snippet from Web API layer. – monstro Jan 19 '17 at 20:42
  • @Yatrix, mee too, first time I am using Web API 2, and this is what I get. – monstro Jan 19 '17 at 20:43
  • @monstro check this out: http://stackoverflow.com/questions/12334382/net-webapi-serialization-k-backingfield-nastiness – Yatrix Jan 19 '17 at 20:44
  • Interesting. I still don't understand what's causing all that extra garbage on the returned collection, but I suspect that may be why you're experiencing the issue you are. – Lex Jan 19 '17 at 20:53

1 Answers1

0

Use without expression, ng-model

  <input type="text" class="form-control" ng-model="param.Name" />
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • @monstro sorry i missed ng-model – Sajeetharan Jan 19 '17 at 20:29
  • still no result, it seems accessing the property as we normally do (param.Name) doesn't work for some reason – monstro Jan 19 '17 at 20:34
  • question: when you use @monstro, you actually type that "@monstro" or you click somewhere? what is the purpose of using "@monstro"? – monstro Jan 19 '17 at 20:35
  • @monstro it's to alert the specific person that he's addressing them. Adding the name will give you a notification someone responded to you. – Yatrix Jan 19 '17 at 20:36
  • @Yatrix, and this notification appears in "Recent inbox messages" in red? Do I have to manually type it, like I just did or is there a shortcut like "reply to.." ? – monstro Jan 19 '17 at 20:39
  • If you're responding to the person who started the question or answer thread, you can just reply (add comment). If you wanted to address me in _his_ answer, you should use the @ symbol. – Yatrix Jan 19 '17 at 20:41