ASP.NET MVC4入門教程(六):驗(yàn)證編輯方法和編輯視圖
在本節(jié)中,您將開始修改為電影控制器所新加的操作方法和視圖。然后,您將添加一個(gè)自定義的搜索頁(yè)。
在瀏覽器地址欄里追加/Movies, 瀏覽到Movies頁(yè)面。并進(jìn)入編輯(Edit)頁(yè)面。
Edit(編輯)鏈接是由Views\Movies\Index.cshtml視圖中的Html.ActionLink方法所生成的:
@Html.ActionLink("Edit", "Edit", new { id=item.ID })
Html對(duì)象是一個(gè)Helper, 以屬性的形式, 在System.Web.Mvc.WebViewPage基類上公開。 ActionLink是一個(gè)幫助方法,便于動(dòng)態(tài)生成指向Controller中操作方法的HTML 超鏈接鏈接。ActionLink方法的第一個(gè)參數(shù)是想要呈現(xiàn)的鏈接文本 (例如,<a>Edit Me</a>)。第二個(gè)參數(shù)是要調(diào)用的操作方法的名稱。最后一個(gè)參數(shù)是一個(gè)匿名對(duì)象,用來(lái)生成路由數(shù)據(jù) (在本例中,ID 為 4 的)。
在上圖中所生成的鏈接是http://localhost:xxxxx/Movies/Edit/4默認(rèn)的路由 (在App_Start\RouteConfig.cs 中設(shè)定) 使用的 URL 匹配模式為: {controller}/{action}/{id}。因此,ASP.NET 將http://localhost:xxxxx/Movies/Edit/4轉(zhuǎn)化到Movies 控制器中Edit操作方法,參數(shù)ID等于 4 的請(qǐng)求。查看App_Start\RouteConfig.cs文件中的以下代碼。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
}
您還可以使用QueryString來(lái)傳遞操作方法的參數(shù)。例如,URL: http://localhost:xxxxx/Movies/Edit?ID=4還會(huì)將參數(shù)ID為 4的請(qǐng)求傳遞給Movies控制器的Edit操作方法。
打開Movies控制器。如下所示的兩個(gè)Edit操作方法。
//
// GET: /Movies/Edit/5
public ActionResult Edit(int id = 0)
{
Movie movie = db.Movies.Find(id);
if (movie == null)
{
return HttpNotFound();
}
return View(movie);
}
//
// POST: /Movies/Edit/5
[HttpPost]
public ActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movie);
}
注意,第二個(gè)Edit操作方法的上面有HttpPost屬性。此屬性指定了Edit方法的重載,此方法僅被POST 請(qǐng)求所調(diào)用。您可以將HttpGet屬性應(yīng)用于第一個(gè)編輯方法,但這是不必要的,因?yàn)樗悄J(rèn)的屬性。(操作方法會(huì)被隱式的指定為HttpGet屬性,從而作為HttpGet方法。)
HttpGet Edit方法會(huì)獲取電影ID參數(shù)、 查找影片使用Entity Framework 的Find方法,并返回到選定影片的編輯視圖。如果不帶參數(shù)調(diào)用Edit 方法,ID 參數(shù)被指定為默認(rèn)值 零。如果找不到一部電影,則返回HttpNotFound 。當(dāng)VS自動(dòng)創(chuàng)建編輯視圖時(shí),它會(huì)查看Movie類并為類的每個(gè)屬性創(chuàng)建用于Render的<label>和<input>的元素。下面的示例為自動(dòng)創(chuàng)建的編輯視圖:
@model MvcMovie.Models.Movie
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Movie</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Genre)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Genre)
@Html.ValidationMessageFor(model => model.Genre)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
注意,視圖模板在文件的頂部有 @model MvcMovie.Models.Movie 的聲明,這將指定視圖期望的模型類型為Movie。
自動(dòng)生成的代碼,使用了Helper方法的幾種簡(jiǎn)化的 HTML 標(biāo)記。 Html.LabelFor 用來(lái)顯示字段的名稱("Title"、"ReleaseDate"、"Genre"或"Price")。 Html.EditorFor 用來(lái)呈現(xiàn) HTML <input>元素。Html.ValidationMessageFor 用來(lái)顯示與該屬性相關(guān)聯(lián)的任何驗(yàn)證消息。
運(yùn)行該應(yīng)用程序,然后瀏覽URL,/Movies。單擊Edit鏈接。在瀏覽器中查看頁(yè)面源代碼。HTML Form中的元素如下所示:
<form action="/Movies/Edit/4" method="post"> <fieldset>
<legend>Movie</legend>
<input data-val="true" data-val-number="The field ID must be a number." data-val-required="The ID field is required." id="ID" name="ID" type="hidden" value="4" />
<div class="editor-label">
<label for="Title">Title</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="Title" name="Title" type="text" value="Rio Bravo" />
<span class="field-validation-valid" data-valmsg-for="Title" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="ReleaseDate">ReleaseDate</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-date="The field ReleaseDate must be a date." data-val-required="The ReleaseDate field is required." id="ReleaseDate" name="ReleaseDate" type="text" value="4/15/1959 12:00:00 AM" />
<span class="field-validation-valid" data-valmsg-for="ReleaseDate" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Genre">Genre</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="Genre" name="Genre" type="text" value="Western" />
<span class="field-validation-valid" data-valmsg-for="Genre" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Price">Price</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-number="The field Price must be a number." data-val-required="The Price field is required." id="Price" name="Price" type="text" value="2.99" />
<span class="field-validation-valid" data-valmsg-for="Price" data-valmsg-replace="true"></span>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
</form>
被<form> HTML 元素所包括的 <input> 元素會(huì)被發(fā)送到,form的action屬性所設(shè)置的URL:/Movies/Edit。單擊Edit按鈕時(shí),from數(shù)據(jù)將會(huì)被發(fā)送到服務(wù)器。
處理 POST 請(qǐng)求
下面的代碼顯示了Edit操作方法的HttpPost處理:
[HttpPost]
public ActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movie);
}
ASP.NET MVC 模型綁定 接收f(shuō)orm所post的數(shù)據(jù),并轉(zhuǎn)換所接收的movie請(qǐng)求數(shù)據(jù)從而創(chuàng)建一個(gè)Movie對(duì)象。ModelState.IsValid方法用于驗(yàn)證提交的表單數(shù)據(jù)是否可用于修改(編輯或更新)一個(gè)Movie對(duì)象。如果數(shù)據(jù)是有效的電影數(shù)據(jù),將保存到數(shù)據(jù)庫(kù)的Movies集合(MovieDBContext instance)。通過(guò)調(diào)用MovieDBContext的SaveChanges方法,新的電影數(shù)據(jù)會(huì)被保存到數(shù)據(jù)庫(kù)。數(shù)據(jù)保存之后,代碼會(huì)把用戶重定向到MoviesController類的Index操作方法,頁(yè)面將顯示電影列表,同時(shí)包括剛剛所做的更新。
如果form發(fā)送的值不是有效的值,它們將重新顯示在form中。Edit.cshtml視圖模板中的Html.ValidationMessageFor Helper將用來(lái)顯示相應(yīng)的錯(cuò)誤消息。
注意,為了使jQuery支持使用逗號(hào)的非英語(yǔ)區(qū)域的驗(yàn)證 ,需要設(shè)置逗號(hào)(",")來(lái)表示小數(shù)點(diǎn),你需要引入globalize.js并且你還需要具體的指定cultures/globalize.cultures.js文件 (地址在https://github.com/jquery/globalize) 在 JavaScript 中可以使用 Globalize.parseFloat。下面的代碼展示了在"FR-FR" Culture下的 Views\Movies\Edit.cshtml 視圖:
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script src="~/Scripts/globalize.js"></script>
<script src="~/Scripts/globalize.culture.fr-FR.js"></script>
<script>
$.validator.methods.number = function (value, element) {
return this.optional(element) ||
!isNaN(Globalize.parseFloat(value));
}
$(document).ready(function () {
Globalize.culture('fr-FR');
});
</script>
<script>
jQuery.extend(jQuery.validator.methods, {
range: function (value, element, param) {
//Use the Globalization plugin to parse the value
var val = $.global.parseFloat(value);
return this.optional(element) || (
val >= param[0] && val <= param[1]);
}
});
</script>
}
十進(jìn)制字段可能需要逗號(hào),而不是小數(shù)點(diǎn)。作為臨時(shí)的修復(fù),您可以向項(xiàng)目根 web.config 文件添加的全球化設(shè)置。下面的代碼演示設(shè)置為美國(guó)英語(yǔ)的全球化文化設(shè)置。
<system.web> <globalization culture ="en-US" /> <!--elements removed for clarity--> </system.web>
所有HttpGet方法都遵循類似的模式。它們獲取影片對(duì)象 (或?qū)ο蠹?,如Index里的對(duì)象集合),并將模型傳遞給視圖。Create方法將一個(gè)空的Movie對(duì)象傳遞給創(chuàng)建視圖。創(chuàng)建、 編輯、 刪除或以其它方式修改數(shù)據(jù)的方法都是HttpPost方法。使用HTTP GET 方法來(lái)修改數(shù)據(jù)是存在安全風(fēng)險(xiǎn),在ASP.NET MVC Tip #46 – Don't use Delete Links because they create Security Holes的Blog中有完整的敘述。在 GET 方法中修改數(shù)據(jù)還違反了 HTTP 的最佳做法和Rest架構(gòu)模式, GET 請(qǐng)求不應(yīng)更改應(yīng)用程序的狀態(tài)。換句話說(shuō),執(zhí)行 GET 操作,應(yīng)該是一種安全的操作,沒有任何副作用,不會(huì)修改您持久化的數(shù)據(jù)。
添加一個(gè)搜索方法和搜索視圖
在本節(jié)中,您將添加一個(gè)搜索電影流派或名稱的SearchIndex操作方法。這將可使用/Movies/SearchIndex URL。該請(qǐng)求將顯示一個(gè) HTML 表單,其中包含輸入的元素,用戶可以輸入一部要搜索的電影。當(dāng)用戶提交窗體時(shí),操作方法將獲取用戶輸入的搜索條件并在數(shù)據(jù)庫(kù)中搜索。
顯示 SearchIndex 窗體
通過(guò)將SearchIndex操作方法添加到現(xiàn)有的MoviesController類開始。該方法將返回一個(gè)視圖包含一個(gè) HTML 表單。如下代碼:
public ActionResult SearchIndex(string searchString)
{
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
return View(movies);
}
SearchIndex方法的第一行創(chuàng)建以下的LINQ查詢,以選擇看電影:
var movies = from m in db.Movies
select m;
查詢?cè)谶@一點(diǎn)上,只是定義,并還沒有執(zhí)行到數(shù)據(jù)上。
如果searchString參數(shù)包含一個(gè)字符串,可以使用下面的代碼,修改電影查詢要篩選的搜索字符串:
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
上面s => s.Title 代碼是一個(gè)Lambda 表達(dá)式。Lambda 是基于方法的LINQ查詢,(例如上面的where查詢)在上面的代碼中使用了標(biāo)準(zhǔn)查詢參數(shù)運(yùn)算符的方法。當(dāng)定義LINQ查詢或修改查詢條件時(shí)(如調(diào)用Where 或OrderBy方法時(shí),不會(huì)執(zhí)行 LINQ 查詢。相反,查詢執(zhí)行會(huì)被延遲,這意味著表達(dá)式的計(jì)算延遲,直到取得實(shí)際的值或調(diào)用ToList方法。在SearchIndex示例中,SearchIndex 視圖中執(zhí)行查詢。有關(guān)延遲的查詢執(zhí)行的詳細(xì)信息,請(qǐng)參閱Query Execution.
現(xiàn)在,您可以實(shí)現(xiàn)SearchIndex視圖并將其顯示給用戶。在SearchIndex方法內(nèi)單擊右鍵,然后單擊添加視圖。在添加視圖對(duì)話框中,指定你要將Movie對(duì)象傳遞給視圖模板作為其模型類。在框架模板列表中,選擇列表,然后單擊添加.
當(dāng)您單擊添加按鈕時(shí),創(chuàng)建了Views\Movies\SearchIndex.cshtml視圖模板。因?yàn)槟氵x中了框架模板的列表,Visual Studio 將自動(dòng)生成列表視圖中的某些默認(rèn)標(biāo)記??蚣苣0鎰?chuàng)建了 HTML 表單。它會(huì)檢查Movie類,并為類的每個(gè)屬性創(chuàng)建用來(lái)展示的<label>元素。下面是生成的視圖:
@model IEnumerable<MvcMovie.Models.Movie>
@{
ViewBag.Title = "SearchIndex";
}
<h2>SearchIndex</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Title
</th>
<th>
ReleaseDate
</th>
<th>
Genre
</th>
<th>
Price
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
運(yùn)行該應(yīng)用程序,然后轉(zhuǎn)到 /Movies/SearchIndex。追加查詢字符串到URL如?searchString=ghost。顯示已篩選的電影。
如果您更改SearchIndex方法的簽名,改為參數(shù)id,在Global.asax文件中設(shè)置的默認(rèn)路由將使得: id參數(shù)將匹配{id}占位符。
{controller}/{action}/{id}
原來(lái)的SearchIndex方法看起來(lái)是這樣的:
public ActionResult SearchIndex(string searchString)
{
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
return View(movies);
}
修改后的SearchIndex方法將如下所示:
public ActionResult SearchIndex(string id)
{
string searchString = id;
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
return View(movies);
}
您現(xiàn)在可以將搜索標(biāo)題作為路由數(shù)據(jù) (部分URL) 來(lái)替代QueryString。
但是,每次用戶想要搜索一部電影時(shí), 你不能指望用戶去修改 URL。所以,現(xiàn)在您將添加 UI頁(yè)面,以幫助他們?nèi)ズY選電影。如果您更改了的SearchIndex方法來(lái)測(cè)試如何傳遞路由綁定的 ID 參數(shù),更改它,以便您的SearchIndex方法采用字符串searchString參數(shù):
public ActionResult SearchIndex(string searchString)
{
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
return View(movies);
}
打開Views\Movies\SearchIndex.cshtml文件,并在 @Html.ActionLink("Create New", "Create")后面,添加以下內(nèi)容:
@using (Html.BeginForm()){
<p> Title: @Html.TextBox("SearchString")<br />
<input type="submit" value="Filter" /></p>
}
下面的示例展示了添加后, Views\Movies\SearchIndex.cshtml 文件的一部分:
@model IEnumerable<MvcMovie.Models.Movie>
@{
ViewBag.Title = "SearchIndex";
}
<h2>SearchIndex</h2>
<p>
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm()){
<p> Title: @Html.TextBox("SearchString") <br />
<input type="submit" value="Filter" /></p>
}
</p>
Html.BeginForm Helper創(chuàng)建開放<form>標(biāo)記。Html.BeginForm Helper將使得, 在用戶通過(guò)單擊篩選按鈕提交窗體時(shí),窗體Post本Url。運(yùn)行該應(yīng)用程序,請(qǐng)嘗試搜索一部電影。
SearchIndex沒有HttpPost 的重載方法。你并不需要它,因?yàn)樵摲椒ú⒉桓膽?yīng)用程序數(shù)據(jù)的狀態(tài),只是篩選數(shù)據(jù)。
您可以添加如下的HttpPost SearchIndex 方法。在這種情況下,請(qǐng)求將進(jìn)入HttpPost SearchIndex方法, HttpPost SearchIndex方法將返回如下圖的內(nèi)容。
[HttpPost]
public string SearchIndex(FormCollection fc, string searchString)
{
return "<h3> From [HttpPost]SearchIndex: " + searchString + "</h3>";
}
但是,即使您添加此HttpPost SearchIndex 方法,這一實(shí)現(xiàn)其實(shí)是有局限的。想象一下您想要添加書簽給特定的搜索,或者您想要把搜索鏈接發(fā)送給朋友們,他們可以通過(guò)單擊看到一樣的電影搜索列表。請(qǐng)注意 HTTP POST 請(qǐng)求的 URL 和GET 請(qǐng)求的URL 是相同的(localhost:xxxxx/電影/SearchIndex)— — 在 URL 中沒有搜索信息?,F(xiàn)在,搜索字符串信息作為窗體字段值,發(fā)送到服務(wù)器。這意味著您不能在 URL 中捕獲此搜索信息,以添加書簽或發(fā)送給朋友。
解決方法是使用重載的BeginForm ,它指定 POST 請(qǐng)求應(yīng)添加到 URL 的搜索信息,并應(yīng)該路由到 HttpGet SearchIndex 方法。將現(xiàn)有的無(wú)參數(shù)BeginForm 方法,修改為以下內(nèi)容:
@using (Html.BeginForm("SearchIndex","Movies",FormMethod.Get))
現(xiàn)在當(dāng)您提交搜索,該 URL 將包含搜索的查詢字符串。搜索還會(huì)請(qǐng)求到 HttpGet SearchIndex操作方法,即使您也有一個(gè)HttpPost SearchIndex方法。

按照電影流派添加搜索
如果您添加了HttpPost 的SearchIndex方法,請(qǐng)立即刪除它。
接下來(lái),您將添加功能可以讓用戶按流派搜索電影。將SearchIndex方法替換成下面的代碼:
public ActionResult SearchIndex(string movieGenre, string searchString)
{
var GenreLst = new List<string>();
var GenreQry = from d in db.Movies
orderby d.Genre
select d.Genre;
GenreLst.AddRange(GenreQry.Distinct());
ViewBag.movieGenre = new SelectList(GenreLst);
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
if (string.IsNullOrEmpty(movieGenre))
return View(movies);
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
}
這版的SearchIndex方法將接受一個(gè)附加的movieGenre參數(shù)。前幾行的代碼會(huì)創(chuàng)建一個(gè)List對(duì)象來(lái)保存數(shù)據(jù)庫(kù)中的電影流派。
下面的代碼是從數(shù)據(jù)庫(kù)中檢索所有流派的 LINQ 查詢。
var GenreQry = from d in db.Movies
orderby d.Genre
select d.Genre;
該代碼使用泛型 List集合的 AddRange方法將所有不同的流派,添加到集合中的。(使用 Distinct修飾符,不會(huì)添加重復(fù)的流派 -- 例如,在我們的示例中添加了兩次喜劇)。該代碼然后在ViewBag對(duì)象中存儲(chǔ)了流派的數(shù)據(jù)列表。
下面的代碼演示如何檢查movieGenre參數(shù)。如果它不是空的,代碼進(jìn)一步指定了所查詢的電影流派。
if (string.IsNullOrEmpty(movieGenre))
return View(movies);
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
在SearchIndex 視圖中添加選擇框支持按流派搜索
在TextBox Helper之前添加 Html.DropDownList Helper到Views\Movies\SearchIndex.cshtml文件中。添加完成后,如下面所示:
<p>
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm("SearchIndex","Movies",FormMethod.Get)){
<p>Genre: @Html.DropDownList("movieGenre", "All")
Title: @Html.TextBox("SearchString")
<input type="submit" value="Filter" /></p>
}
</p>
運(yùn)行該應(yīng)用程序并瀏覽 /Movies/SearchIndex。按流派、 按電影名,或者同時(shí)這兩者,來(lái)嘗試搜索。
在這一節(jié)中您修改了CRUD 操作方法和框架所生成的視圖。您創(chuàng)建了一個(gè)搜索操作方法和視圖,讓用戶可以搜索電影標(biāo)題和流派。在下一節(jié)中,您將看到如何將屬性添加到Movie模型,以及如何添加一個(gè)初始設(shè)定并自動(dòng)創(chuàng)建一個(gè)測(cè)試數(shù)據(jù)庫(kù)。
- asp.net下gridview 批量刪除的實(shí)現(xiàn)方法
- Asp.Net+XML操作基類(修改,刪除,新增,創(chuàng)建)
- asp.net GridView 刪除時(shí)彈出確認(rèn)對(duì)話框(包括內(nèi)容提示)
- asp.net中g(shù)ridview的查詢、分頁(yè)、編輯更新、刪除的實(shí)例代碼
- asp.net 編輯gridview的小例子
- Asp.net的GridView控件實(shí)現(xiàn)單元格可編輯方便用戶使用
- 在ASP.NET 2.0中操作數(shù)據(jù)之十六:概述插入、更新和刪除數(shù)據(jù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之十七:研究插入、更新和刪除的關(guān)聯(lián)事件
- 在ASP.NET 2.0中操作數(shù)據(jù)之十九:給編輯和新增界面增加驗(yàn)證控件
- 在ASP.NET 2.0中操作數(shù)據(jù)之二十二:為刪除數(shù)據(jù)添加客戶端確認(rèn)
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十六:在DataList里編輯和刪除數(shù)據(jù)概述
相關(guān)文章
在ASP.NET 2.0中操作數(shù)據(jù)之二十四:分頁(yè)和排序報(bào)表數(shù)據(jù)
本文主要介紹ASP.NET 2.0中使用GirdView控件呈現(xiàn)數(shù)據(jù)時(shí)如何實(shí)現(xiàn)分頁(yè)和排序功能的,希望對(duì)大家有所幫助。2016-05-05
在ASP.NET 2.0中操作數(shù)據(jù)之六十五:在TableAdapters中創(chuàng)建新的存儲(chǔ)過(guò)程
本文主要講解使用TableAdapter設(shè)置向?qū)ё詣?dòng)創(chuàng)建增刪改查的存儲(chǔ)過(guò)程,雖然自動(dòng)創(chuàng)建存儲(chǔ)過(guò)程可以節(jié)省時(shí)間,但他們會(huì)包含一些無(wú)用的參數(shù),下節(jié)我們會(huì)介紹TableAdapter使用現(xiàn)有的存儲(chǔ)過(guò)程。2016-05-05
MongoDB數(shù)據(jù)庫(kù)介紹并用.NET?Core對(duì)其進(jìn)行編碼
這篇文章介紹了MongoDB數(shù)據(jù)庫(kù)并用.NET?Core對(duì)其進(jìn)行編碼,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02
在ASP.NET 2.0中操作數(shù)據(jù)之二十五:大數(shù)據(jù)量時(shí)提高分頁(yè)的效率
上一篇我們介紹過(guò)利用GirdView控件內(nèi)置的分頁(yè)功能進(jìn)行分頁(yè),但是熟悉ASP.NET的人都知道,那不是真正意義上的分頁(yè),本文就帶著大家利用利用存儲(chǔ)過(guò)程創(chuàng)建高效的分頁(yè)。2016-05-05
在ASP.NET 2.0中操作數(shù)據(jù)之一:創(chuàng)建一個(gè)數(shù)據(jù)訪問(wèn)層
本文主要介紹創(chuàng)建數(shù)據(jù)訪問(wèn)層的具體步驟,從配置數(shù)據(jù)庫(kù)連接到插入,更新和刪除數(shù)據(jù)的具體實(shí)現(xiàn)方法,希望對(duì)大家有所幫助。2016-04-04
在ASP.NET 2.0中操作數(shù)據(jù)之七十一:保護(hù)連接字符串及其它設(shè)置信息
默認(rèn)情況下,ASP.NET應(yīng)用程序數(shù)據(jù)庫(kù)連接字符串、用戶名和密碼等敏感信息都是保存在根目錄的web.config文件中,我們可以使用加密算法對(duì)其加密,從而保證這些敏感信息不被泄漏。2016-05-05
ASP.NET:ADO.NET的DataAdapter對(duì)象
ASP.NET:ADO.NET的DataAdapter對(duì)象...2006-10-10
為Visual Studio手工安裝微軟ReportViewer控件
這篇文章介紹了為Visual Studio手工安裝微軟ReportViewer控件的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06












