Adding Phone field in ContactUs form giving error 'ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
One or more compilation failures occurred:
tmlvzkxy.asb(918,1871): error CS1031: Type expected
tmlvzkxy.asb(918,2055): error CS1031: Type expected
tmlvzkxy.asb(918,2239): error CS1031: Type expected
tmlvzkxy.asb(918,1919): error CS1061: 'ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting a first argument of type 'ContactUsModel' could be found (are you missing a using directive or an assembly reference?)
tmlvzkxy.asb(918,2103): error CS1061: 'ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting a first argument of type 'ContactUsModel' could be found (are you missing a using directive or an assembly reference?)
tmlvzkxy.asb(918,2287): error CS1061: 'ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting a first argument of type 'ContactUsModel' could be found (are you missing a using directive or an assembly reference?)


Presentation\Nop.Web\Themes\Flexo\Views\Common\ContactUs.cshtml (I am using a theme)
<div class="inputs">
                                <label asp-for="Phone" asp-postfix=":"></label>
                                <input asp-for="Phone" placeholder="@T("ContactUs.Phone.Hint")" class="phone" />
                                <nop-required />
                                <span asp-validation-for="Phone"></span>
                            </div>

Presentation\Nop.Web\Models\Common\ContactUsModel.cs
[Required]
        [DataType(DataType.PhoneNumber)]
        [NopResourceDisplayName("ContactUs.Phone")]
        public string Phone { get; set; }


Can anyone help with error.
4 years ago
go to contact us view and from view goto model and let again that is this the correct model that added this property.

this error clearly mention that "Phone" property not exist into ContactUsModel class.
Same name model exist multiple time into project.
4 years ago
sak233212 wrote:

...
tmlvzkxy.asb(918,1919): error CS1061: 'ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting a first argument of type 'ContactUsModel' could be found (are you missing a using directive or an assembly reference?)
...

Presentation\Nop.Web\Themes\Flexo\Views\Common\ContactUs.cshtml (I am using a theme)
<div class="inputs">
    <label asp-for="Phone" asp-postfix=":"></label>
    <input asp-for="Phone" placeholder="@T("ContactUs.Phone.Hint")" class="phone" />
    <nop-required />
    <span asp-validation-for="Phone"></span>
</div>

Presentation\Nop.Web\Models\Common\ContactUsModel.cs
[Required]
[DataType(DataType.PhoneNumber)]
[NopResourceDisplayName("ContactUs.Phone")]
public string Phone { get; set; }


I have just made the changes that you have provided here to the latest version of nopcommerce 4.2 and can confirm that it is passing the information correctly.  I have a breakpoint set on the CommonController.ContactUsSend(ContactUsModel, bool) HttpPost method and can confirm that the phone number is passed to that controller method.

The error message suggests that your model does not have the Phone property though.

Assuming you have performed the exact changes to the files mentioned above, then I would perform a clean and rebuild to ensure that those changes to the model have been copied to the bin directory.  Check the Error List/Output windows for any errors and ensure you are not running a previously working build.  I can't see any reason why your changes should not be working.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.