Reputation: 71
Why I can't find the model on the image:
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:
@*
For more information on enabling MVC for 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 the form in the middle of the 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 a button we can use bootstrap to make it nice using font-awesome
Added at the bower.json file
<i class="fa fa-angle-left></i>-->
</div>
<!--This will show the message received on this case if the mail was 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
is not being recognize.
Thank you in advance
Upvotes: 1
Views: 63
Reputation: 23220
You are just using the wrong namespace.
Your ViewModel is defined into Moran.ViewModels
namespace instead of BazarMoran.ViewModels
.
Then you must use
@model Moran.ViewModels.ContactViewModel
Instead of
@model BazarMoran.ViewModels.ContactViewModel
Or just change the namespace into your ContactViewModel
class to be BazarMoran.ViewModels
.
Upvotes: 1