```csharp
// home/index.cshtml
@{
//C# code
Layout = null;
int m = 10;
string s = "<h1>hello</h1>";
<div>HTML Tag</div>
@:text...
<text>
aaa
bbb
cc
</text>
}
@{
string[] items = { "item1", "item2", "item3" };
foreach (var item in items)
{
<div>@item</div>
}
}
@foreach (var item in items)
{
<div>@item</div>
}
@@
aaa@aaa.bbb
m
@m
@m+50
@(m+50)
@s
@Html.Raw(s)
//================================
//operacontroller.cs
public async Task<ActionResult> FilterData(int number)
{
//LINQ
var query=(from opera in context.Operas
orderby opera.Year descending
select opera).Take(number);
return View(nameof(Index),await query.ToListAsync());
}
// opera/index.cshtml
@using (Html.BeginForm("filterdata","opera",FormMethod.Get))
{
@:Number: <input type="text" name="number" />
<input type="submit" />
}
//operacontext.cs
public class OperaContext:DbContext
{
public OperaContext()
{
Database.Log =s=> Debug.WriteLine(s);
}
public DbSet<Opera> Operas { get; set; }
}
//=================================
// comment.cs
public class Comment
{
public int Id { get; set; }
public string Subject { get; set; }
[DataType(DataType.MultilineText)]
public string HtmlComment { get; set; }
public int? Price { get; set; }
public bool IsApprove { get; set; }
}
// commentcontroller.cs
public class CommentController : Controller
{
// GET: Comment
public ActionResult Index()
{
return View();
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Comment comment)
{
return Json(comment);
}
}
// home/index.cshtml
<h1>Home</h1>
@Html.ActionLink("Opera List","Index","Opera") |
@Html.ActionLink("Comment Create","Create","Comment")
//===============================
// commentcontroller.cs
public ActionResult GetComments()
{
List<Comment> data = new List<Comment> {
new Comment{Id=100,Subject="A"},
new Comment{Id=200,Subject="B"},
new Comment{Id=300,Subject="C"}
};
return View(data);
}
public ActionResult GetOtherComments()
{
List<Comment> data = new List<Comment> {
new Comment{Id=400,Subject="D"},
new Comment{Id=500,Subject="E"},
new Comment{Id=600,Subject="F"}
};
return View(data);
}
// comment/getcommemnts.cshtml
<h1>GetComments</h1>
<ul>
@foreach (var item in Model)
{
<li>@item.Subject</li>
}
</ul>
// comment/getothercommemnts.cshtml
<h1>GetOtherComments</h1>
<ul>
@foreach (var item in Model)
{
<li>@item.Subject</li>
}
</ul>
// home/index.cshtml
@Html.ActionLink("Opera List", "Index", "Opera") |
@Html.ActionLink("Comment Create", "Create", "Comment") |
@Html.ActionLink("GetComments", "GetComments", "Comment") |
//===============================
// shared/_commentlist.cshtml
@model IEnumerable<Mod02.Models.Comment>
<ul style="background-color:yellow;">
@foreach (var item in Model)
{
<li>@item.Subject</li>
}
</ul>
// comment/getcommemnts.cshtml
<h1>GetComments</h1>
@Html.Partial("_CommentList")
// comment/getothercommemnts.cshtml
<h1>GetOtherComments</h1>
@Html.Partial("_CommentList")
//==========================
// commentcontroller.cs
public ActionResult GetAllComments()
{
List<Comment> data = new List<Comment> {
new Comment{Id=100,Subject="A"},
new Comment{Id=200,Subject="B"},
new Comment{Id=300,Subject="C"},
new Comment{Id=400,Subject="D"},
new Comment{Id=500,Subject="E"},
new Comment{Id=600,Subject="F"}
};
return View("_CommentList", data);
}
// home/index.cshtml
@Html.Action("GetAllComments","Comment")
//=========================
// commentcontroller.cs
public ActionResult GetAllComments(string color)
{
ViewBag.color = color;
List<Comment> data = new List<Comment> {
new Comment{Id=100,Subject="A"},
new Comment{Id=200,Subject="B"},
new Comment{Id=300,Subject="C"},
new Comment{Id=400,Subject="D"},
new Comment{Id=500,Subject="E"},
new Comment{Id=600,Subject="F"}
};
return View("_CommentList", data);
}
// home/index.cshtml
@Html.Action("GetAllComments","Comment", new {color="pink"})
```