0

I have an asp mvc application. It has a layout page. like

Layout

<header>...</header>
<body>
<div main ...>
<footer>
<!--This is Where Error appears-->
@{Html.RenderPartial("~/Views/Shared/_Footer.cshtml");}  
</footer>
</body>
<scripts ...

Another form that looks like

Contact Form this works

@model CHPIMSWebsite.Models.tblfeedback
<div class="container">
   @using (Html.BeginForm(FormMethod.Post))
   {
    ...
   }
</div>

It works.

Now I have another form, similar but with only change that it also uploads an image but it is separate like..

SZBMU_Form causes conflicts

@model CHPIMSWebsite.Models.SZBMU_Form
<div class="container">
   @using (Html.BeginForm("AddSZBMU_Form", "CHPIMS", FormMethod.Post, new { id = "myForm", FormMethod.Post, enctype = "multipart/form-data" }))
{
 ...
}
</div>

In case of Contact Us form nothing wrong happens, form loads properly but when I load SZBMU_Form it gives error as shown below. The footer page looks like this

This loads in footer

@model CHPIMSWebsite.Models.tblNewsLetter
<div class="container">
   @using (Html.BeginForm(FormMethod.Post))
   {
    ...
   }
</div>

The model item passed into the dictionary is of type 'CHPIMSWebsite.Models.SZBMU_Form', but this dictionary requires a model item of type 'CHPIMSWebsite.Models.tblNewsLetter'

Why it conflicts in case of second form and not first while footer form is same in both cases. Is it any why with out specifying model in footer or using Viewmodel?

abdul qayyum
  • 535
  • 1
  • 17
  • 39
  • 1
    It's failing because `CHPIMSWebsite.Models.tblNewsLetter` is not `CHPIMSWebsite.Models.SZBMU_Form`, as the error says... You've defined your footer to only take the first type. You'll have to specify the model when calling `RenderPartial` – Heretic Monkey Oct 31 '18 at 17:24
  • @HereticMonkey yes I do understand that it is the problem but it is not occurring in the case of contact form? – abdul qayyum Oct 31 '18 at 17:30
  • What's the "contact form"? You might be able to tell from the code you've posted, but I can't :). – Heretic Monkey Oct 31 '18 at 17:32
  • I have edited question to label all forms – abdul qayyum Oct 31 '18 at 17:34
  • Well, that form uses the same type as the footer. In other words, it works because `CHPIMSWebsite.Models.tblNewsLetter` **is** `CHPIMSWebsite.Models.tblNewsLetter`. – Heretic Monkey Oct 31 '18 at 17:40
  • No it uses `tblfeedback`, but I have figured out the issue, from controller I send a different model in `SZBMU_Form`, this is why it is causing issue. Thank you for the help though – abdul qayyum Oct 31 '18 at 17:45

0 Answers0