我有一個註冊表格(我正在與ASP.NET MVC),我試圖解析每個字段的內容到我的數據庫,但我真的不知道如何做這個。把數據從一個註冊表格數據庫
首先,我不知道應該把數據庫連接到哪裏。它應該在我的註冊控制器內嗎?對不起,如果它聽起來有點傻,但我是所有這些東西的新手!下面的代碼是從我的註冊表單視圖
@model Client.Models.RegisterModel
@{
ViewBag.Title = "Register";
}
@using (Html.BeginForm("Register", "Register", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Create a new account.</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.Name, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Surname, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Surname, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Number, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Number, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.address, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.address, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.postcode, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.postcode, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.female, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.CheckBoxFor(m => m.female, new { @class = "col-md-2 control-label" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.male, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.CheckBoxFor(m => m.male, new { @class = "col-md-2 control-label" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Υποβολή" />
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
這是一個基本問題,你應該對此做一些研究,例如 - http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing -basic-crud-functional-with-the-entity-framework-in-asp-net-mvc-application – ramiramilu