Compiling Error - Trying to insert a Client in a Asp .Net MVC Client_Index

  • Thread starter Thread starter F.oliveirarocha
  • Start date Start date
F

F.oliveirarocha

Guest
Hi folks, This is my first projet in Asp .Net MVC, I'm starting a Client File, Insert and then consult.

I'm getting an Error trying to insert a new client. The Table Client -> "ClientID" is Identity.

I can't figure out where is the Error, after 8 hours at the screen. Please help me out.

Here follows the Error Message:


Erro de Servidor no Aplicativo '/'.

Erro de Compilação

Descrição: Erro ao compilar um recurso necessário para atender esta solicitação. Examine os detalhes específicos do erro e modifique o código fonte apropriadamente.

Mensagem de Erro do Compilador: CS0234: The type or namespace name 'Models' does not exist in the namespace 'AutocarWeb' (are you missing an assembly reference?)

Erro de Origem:

Linha 29:
Linha 30:
Linha 31: public class _Page_Views_Client_Index_cshtml : System.Web.Mvc.WebViewPage<IEnumerable<AutocarWeb.Models.ClientBusinessConsulting>> {
Linha 32:
Linha 33: #line hidden


Arquivo de Origem: C:\Users\foliv\AppData\Local\Temp\Temporary ASP.NET Files\vs\c271e5ef\5fe161e\App_Web_index.cshtml.a673969b.ekxut6e2.0.cs Linha: 31
Mostrar Saída Detalhada do Compilador:
Mostrar Origem de Compilação Completa:



Informações sobre a Versão: Microsoft .NET Framework Versão:4.0.30319; Versão do ASP.NET:4.8.3928.0

Now I will Include de programming Code.

@model IEnumerable<AutocarWeb.Models.ClientBusinessConsulting>

@{
ViewBag.Title = "Clients";
}

<h2>Clients</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ClienteID)
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th> // not compiling
<th>
@Html.DisplayNameFor(model => model.County)
</th>
<th>
@Html.DisplayNameFor(model => model.celular_phone)
</th>
<th></th>
</tr>

@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ClienteID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td> //not compiling
<td>
@Html.DisplayFor(modelItem => item.County)
</td>
<td>
@Html.DisplayFor(modelItem => item.celular_phone)
</td>
<td>
@Html.ActionLink("Editar", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Detalhes", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Excluir", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}

</table>


ClientViewModel:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Domain;
using System.Linq;
using System.Web;

namespace AutocarWeb.ViewModels
{
public class ClientViewModel
{
public int ClientID { get; set; }
public string Name { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string Address { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string City { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string County { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string State { get; set; }
public string Zip_Code { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string CPF { get; set; }
public string Idnumber { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string email { get; set; }
[Required(ErrorMessage = "* Campo com preenchimento obrigatório")]
public string celular_phone { get; set; }
public string home_phone { get; set; }

public ClientViewModel()
{

}

public ClientViewModel(Client client)
{
ClientID = client.ClientID;
Name = client.Name;
Address = client.Address;
City = client.City;
County = client.County;
State = client.State;
Zip_Code = client.Zip_Code;
CPF = client.CPF;
Idnumber = client.Idnumber;
email = client.email;
celular_phone = client.celular_phone;
home_phone = client.home_phone;

}
}



}

ClientController

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutocarWebConnection.Interface;
using System.Domain;
using System.Domain.Business;
using System.Domain.Interfaces;
using System.Domain.Repositories;
using AutocarWeb.ViewModels;

namespace AutocarWeb.Controllers
{
public class ClientController : Controller
{
private ClientBusiness clientBusiness = new ClientBusiness();
// GET: Client
public ActionResult Index()
{
var clients = clientBusiness.ListallClients();
return View(clients);
}

[HttpGet]
public ActionResult Insert()
{
return View();
}

[HttpPost]
public ActionResult Insert(ClientViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}

var client = new Client
{
Name = model.Name,
Address = model.Address,
City = model.City,
County = model.County,
State = model.State,
Zip_Code = model.Zip_Code,
CPF = model.CPF,
Idnumber = model.Idnumber,
email = model.email,
celular_phone = model.celular_phone,
home_phone = model.home_phone
};

clientBusiness.Save(client);
return RedirectToAction("Index");
}

}


}

Insert.cshtml

@model AutocarWeb.ViewModels.ClientViewModel

@{
ViewBag.Title = "Insert";
}

<h2>Client File</h2>


@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>ClientViewModel</h4>
<hr />


<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.County, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.County, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.County, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.State, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.State, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.State, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Zip_Code, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Zip_Code, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Zip_Code, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.CPF, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CPF, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CPF, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Idnumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Idnumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Idnumber, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.celular_phone, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.celular_phone, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.celular_phone, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.home_phone, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.home_phone, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.home_phone, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Insert" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

Continue reading...
 
Back
Top