AspNetCore 2.0 MVC / 'model' must appear at the start line
Asked Answered
D

3

8

_Create.cshtml (snippet)

@model MC.Models.AdminViewModels.NewUserViewModel

@await Html.PartialAsync("_ModalHeader", new ModalHeader() { Title= "New User"})
<div class="modal-body">
<form asp-action="Create">
    <div class="form-horizontal">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <div class="form-group">
            <label asp-for="NewUser.FirstName" class="col-md-4 control-label">First Name</label>
            <div class="col-md-8">
                <input asp-for="NewUser.FirstName" class="form-control" />
                <span asp-validation-for="NewUser.FirstName" class="text-danger"></span>
            </div>
        </div>

Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred: C:\Projects\Webs\MC\Areas\Admin\Views\Shared_ModalFooter.cshtml(1,3): Error RZ9999: The 'model` directive must appear at the start of the line. at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(String relativePath) at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CreateCacheEntry(String normalizedPath)

_ModalFooter.cshtml (example of nearly exactly what is in _ModalHeader)

@model MC.Models.ModalFooter

<div class="modal-footer">
    <button data-dismiss="modal" id="@Model.CancelButtonID" class="btn btn-default" type="button">@Model.CancelButtonText</button>
@if (!Model.OnlyCancelButton)
{
    <button class="btn btn-success" id="@Model.SubmitButtonID" type="submit">
        @Model.SubmitButtonText
    </button>
}
</div> 

This has thrown me for a loop. Asp.net Core 2.0, works just fine in 1.1.2 but this is thrown for each and ever partial within partial, that is setup for modal use. Error RZ9999 hasn't been documented anywhere apparently. Of course taking out the the partial for straight html doesn't throw the error, but as can imagine that is 1 line verse 3-4 lines of code. I figure I am missing something from Asp.net Core MVC 1.1 to 2.0 conversion somewhere. Also this is partial within a partial.

NOTE: I am using the 'Microsoft.AspNetCore.All' package pull in the *.csproj, since release day NuGet didn't have the EF tools packages for v2.

Deformed answered 19/8, 2017 at 15:11 Comment(0)
D
24

BOM (byte order marker) was the reason there was some junk at the beginning of the file! Edited it with a binary editor boom works.

Deformed answered 19/8, 2017 at 16:30 Comment(2)
This is crazy i deleted the first line in my view retyped it manually and it works i am going to have to assume this was my problem as well. Thanks for the tip.Leisaleiser
It happened to me with blazor wasm. i removed it manually and retyped and it worked. it is crazy indeed.Holmen
R
4

I have to delete and enter the code manually for it to work again

Rycca answered 17/7, 2023 at 14:17 Comment(0)
M
2

Place the cursor before the @ sign and click the backspace few times.

Mcauliffe answered 20/6 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.