私は MVC を初めて使用します。ログイン コントロールを作成したいので、以下のコードをビューに記述しました。
@using (Html.BeginForm("LoginControl", "Login"))
{
<div style="float: left; line-height: 36px;">
@Html.ValidationSummary()
<div style="float: left; margin-right: 20px;">
UserName :
</div>
<div style="float: right;">@Html.TextBoxFor(o => o.login.UserName)
</div>
<br />
<div style="float: left; margin-right: 20px;">
Password :
</div>
<div style="float: right;">@Html.TextBoxFor(o => o.login.UserPassword)</div>
<br />
<div style="float: left; margin-right: 20px;">
</div>
<input type="button" value="Login" id="Login" title="Login" />
</div>
}
コントローラーで私のコードは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication2.Controllers
{
public class LoginController : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
public ActionResult LoginControl(String UserName, String UserPassword)
{
string result = "";
if (UserName == "ram" && UserPassword == "ram123")
{
result = "1";
}
if (result == "1")
{
return View("LoginControl");
}
else
{
ModelState.AddModelError("", "Invalid username or password");
return View("Index");
}
}
}
}
なぜそれが機能しているのかわかりません。助けてください。