asp.net mvc - Trying to add a model to a view but it doesn't show -


why can't find model on image:

enter image description here

contactviewmodel class is:

using system.componentmodel.dataannotations;  namespace moran.viewmodels {     public class contactviewmodel     {         [required]         [stringlength(255, minimumlength = 5)]         public string name { get; set; }         [required]         [emailaddress]         public string email { get; set; }         [required]         [stringlength(1024, minimumlength = 5)]         public string message { get; set; }     } } 

contact.cshtml:

@*     more information on enabling mvc empty projects, visit http://go.microsoft.com/fwlink/?linkid=397860 *@ @model bazarmoran.viewmodels.contactviewmodel @{     viewbag.title = "contact us"; }  @section scripts {     <script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>     <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script> }  <div class="row">     <div class="col-md-6 col-md-offset-3">         <!--leave form in middle of page-->         <h2>contact us</h2>           <form method="post">              <div>                 <div asp-validation-summary="validationsummary.modelonly"></div>                 <div class="form-group">                     <label asp-for="name">name</label>                     <input class="form-control" asp-for="name" />                     <span asp-validation-for="name" class="text-muted"></span>                 </div>             </div>             <div>                 <div class="form-group">                     <label asp-for="email">email</label>                     <input class="form-control" type="email" asp-for="email" />                     <span asp-validation-for="email" class="text-muted"></span>                 </div>             </div>              <div class="form-group">                 <label asp-for="message">message</label>                 <textarea class="form-control" cols="40" rows="4" asp-for="message"></textarea>                 <span asp-validation-for="message" class="text-muted"></span>             </div>              <div class="form-group">                 <a asp-controller="app" asp-action="index" class="btn btn-default">cancel</a>                 <input type="submit" value="send message" class="btn btn-success" />                 <!--with in button can use bootstrap make nice using font-awesome                     added @ bower.json file                     <i class="fa fa-angle-left></i>-->             </div>             <!--this show message received on case if mail sent correctly-->             @if (viewbag.message != null)             {                 <div>@viewbag.message</div>              }          </form>     </div> <!--end class col--> </div> <!--end class row--> 

the line: @model bazarmoran.viewmodels.contactviewmodel not being recognize.

thank in advance

you using wrong namespace.

your viewmodel defined moran.viewmodels namespace instead of bazarmoran.viewmodels.

then must use

@model moran.viewmodels.contactviewmodel  

instead of

@model bazarmoran.viewmodels.contactviewmodel 

or change namespace contactviewmodel class bazarmoran.viewmodels.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -