0

I'm not entirely sure what's going on here, but I am trying to add in the author names (or au_fname) from an author. I want to use the author's name in an autocomplete search. So far this is what I have.

<script type="text/javascript" language="javascript">
        $(function () {            
            var model = @Html.Raw(Json.Serialize(Model));
    var stra = [];
    model.forEach(function (element) {
            stra.push(element.au_fname);
        });
    $("#id").autocomplete({
            source: stra           
    });
});       
</script>

I'm not sure how I am supposed to link the element to be able to access au_fname. Any help would be much appreciated.

Xiaoy312
  • 14,292
  • 1
  • 32
  • 44
Core1211
  • 3
  • 3
  • 1
    Possible duplicate of [Razor MVC Populating Javascript array with Model Array](https://stackoverflow.com/questions/23781034/razor-mvc-populating-javascript-array-with-model-array) – Xiaoy312 Oct 15 '18 at 21:36
  • stra is an array so what this is doing is looping through the Serialized Modal and adding each name(au_fname ) to an array – China Syndrome Oct 15 '18 at 22:12
  • What type is `Model` ? – Shyju Oct 15 '18 at 22:53
  • This should work as long as Model is a collection type of objects with an `au_fname` property. What is happening now ? – Shyju Oct 15 '18 at 23:08
  • Well that problem is the model is not linked to the author model and Im not sure how to get it to bind to that – Core1211 Oct 17 '18 at 03:28

0 Answers0