Crud que no graba nuevos registros
Publicado por Jhon (15 intervenciones) el 08/10/2017 04:50:47
Hola, uso Visual Studio 2015, Sql 2012, Sql Management Studio. Este Crud de internet me elimina y me edita pero no me graba nuevos registros, hace mucho no programo, ¿me podrían decir por qué?
Vista
Controlador
Procedimiento almacenado
AddNewStudent
Vista
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@model CRUDinMVC.Models.StudentModel
@using (Html.BeginForm())
{
<div class="form-horizontal">
<h4>StudentModel</h4>
<hr />
@Html.ValidationSummary(true, "", new {@class = "text-danger" })
<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.City, htmlAttributes: new { @class = "contol-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.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">
<div class = "col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
<h3>@ViewBag.Message</h3>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<script src="~/scripts/jquery-1.10.2.min.js"></script>
<script src="~/scripts/jquery.validate.min.js"></script>
<script src="~/scripts/jquery.validate.unobtrusive.min.js"></script>
Controlador
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// POST: Student/Create
[HttpPost]
public ActionResult Create(StudentModel smodel)
{
try
{
if(ModelState.IsValid)
{
StudentDBHandle sdb = new StudentDBHandle();
if(sdb.AddStudent(smodel))
{
ViewBag.Message = "Student Details Added Successfully";
ModelState.Clear();
}
}
return View();
}
catch
{
return View();
}
}
Procedimiento almacenado
AddNewStudent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
USE [StudenDB]
GO
/****** Object: StoredProcedure [dbo].[AddNewStudent] Script Date: 02/10/2017 7:13:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[AddNewStudent]
@id int,
@Name nvarchar(50),
@City nvarchar(50),
@Address nvarchar(50)
as
begin
insert into dbo.StudentReg values (@id, @Name, @City, @Address)
End
Valora esta pregunta


0