MVC2 및 C#을 사용하여 ASP에서 정말 간단한 양식을 만들려고합니다. 두 개의 요소와 제출 버튼이 있으며 VS2010의 디자이너를 사용하여 양식을 만들었습니다.ASP.NET MVC2 양식 요소 이름
보기 :
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="create_event" runat="server">
<h2>Create</h2>
<p>Event ID:
<asp:TextBox ID="txtEventID" runat="server"></asp:TextBox>
</p>
<p>Event Description:
<asp:TextBox ID="txtEventDescription" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="submit" runat="server" Text="Add Event" />
</p>
</form>
</asp:Content>
내 컨트롤러에서 폼 요소에 액세스 할 때 지금 갖는있어 문제는, 내가 FormCollection 개체를 사용하여 이상한 키 이름을 얻는다.
컨트롤러 :
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
foreach (var key in collection)
{
var ks = key.ToString();
var value = collection[key.ToString()];
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
두 컨트롤의 이름 속성이 ctl00 $ MainContent $ txtEventDescription 및 ctl00 $ MainContent $ txtEventID로 런타임에 설정됩니다 키에 사용됩니다. 디자인 타임에 설정 한 ID로 이러한 항목을 참조 할 수있는 방법이 있습니까? id와 같은 값을 가진 name 속성을 추가하려고 시도했지만 작동하지 않았습니다.
감사합니다.