Login Login
MORE

WIDGETS

Widgets

Wanted articles
Who is online?
Article tools

CSharp:MVC Razor Esempi utili

From Aino Wiki

Jump to: navigation, search

Controllo

IF controllo stringa vuota

Dalla seguente view:

@model string[]
@{
	ViewBag.Title = "Names";
}
<h2>Names</h2>
@if (Model.Length == 0) {
	using(Html.BeginForm()) {
		for (int i = 0; i < 3; i++) {
			<div><label>@(i + 1):</label>@Html.TextBox("names")</div>
		}
		<button type="submit">Submit</button>
		}
	} else {
		foreach (string str in Model) {
			<p>@str</p>
		}
	@Html.ActionLink("Back", "Names");
}

Binding

Collection

@model IList<string>
@{
	ViewBag.Title = "Names";
}
<h2>Names</h2>
@if (Model.Count == 0) {
	using(Html.BeginForm()) {
		for (int i = 0; i < 3; i++) {
			<div><label>@(i + 1):</label>@Html.TextBox("names")</div>
		}
		<button type="submit">Submit</button>
	}
} else {
	foreach (string str in Model) {
		<p>@str</p>
	}
	@Html.ActionLink("Back", "Names");
}



C# | MVC | Razor


Visual Studio

Author Giuseppe AINO