0

I have a partial page which is passed a list of Events (where an event is a custom Model). This works fine:

@model IEnumerable<Entry>
@using MySite.Models

Within the partial page I iterate through the list of Entry's in the model:

    @if (Model.Count() > 0)
    {
        foreach (var entry in Model)
        {
          ...

This works fine as well. However, within this foreach loop I want to send the data of the entry to another partial view:

@await Html.PartialAsync("/Pages/Shared/ShareMedia/shareMedia.cshtml", @entry)

Within this partial I have declared the following:

@model Entry

However this seems t return an error:

error CS0118: 'Entry' is a namespace but is used like a type

If I then try to add the full path of the model

@model MySite.Models.Entry

I get the following error when trying to load the partial:

Uncaught ReferenceError: MySite is not defined
at HTMLImageElement.onclick ((index):1)

Is there any advice anyone might be able to give to help me get around this. I have done some googlinig but not getting any direction.

Any advice is greatly appreciated!

Yiyi You
  • 16,875
  • 1
  • 10
  • 22
CJH
  • 1,266
  • 2
  • 27
  • 61
  • you are mixing up MySight and MySite – Roger Aug 16 '21 at 15:22
  • That is a good spot. MySite/MySight is just a placeholder I typed in to this Stack Overflow question in place of the real placeholder. The real placeholders in my code actually match. Appreciate the response though! I have corrected now. – CJH Aug 16 '21 at 16:22

1 Answers1

0

You'd better don't name a class as the same with a namespace.Try to change the Entry name,for example,EntryModel.And then use

@model IEnumerable<EntryModel>

partial view:

@model EntryModel

Uncaught ReferenceError: MySite is not defined at HTMLImageElement.onclick ((index):1) The error is usually happended when a function in onclick event is not defined.For example:

<button onclick="MySite()">click</button>

and if MySite() is not defined in js,it will get the error.

Yiyi You
  • 16,875
  • 1
  • 10
  • 22
  • Thanks for the response. This is the thing.... I don't have Entry as a Namespace anywhere that I can see, it is just a Model. It is only when I fully qualify the model Entry it recognises it as such. Only then I get the Uncaught ReferenceError mentioned above. – CJH Aug 17 '21 at 15:58
  • Actually, I think the issue is that I need to seralize my model for it to get sent into the Javascript function (which I didnt actually include in the above example!) lol – CJH Aug 17 '21 at 16:26
  • Can you share your js? – Yiyi You Aug 18 '21 at 01:24