2012-07-07 5 views
0

내보기에 시작일 및 검색 날짜가 있습니다.제어 값을 컨트롤러에 게시

이 컨트롤러는 내 컨트롤러에 POST를 보내고 선택한 날짜 사이에 사용 가능한 객실을 검색합니다. 그런 다음 결과가 다시보기에 나열됩니다.

저는 PostBack을 사용할 수있는 WebForms에 익숙하며 모든 제어 데이터를 가져옵니다.하지만 MVC에서는이를 수행 할 수 없습니다.

결과가 표시되면 어떻게 다음, 컨트롤러에 다시 선정 된 RoomId 모두 게시 할 수 있습니다 :

@Html.ActionLink("Book Room","Book", new { id=item.RoomId }) 

을 ... 그리고 tbFrom을하고 TBTO가 텍스트 상자에서 날짜?

내보기는 다음과 같습니다. 어떤 도움을

감사합니다,

마크

@model IEnumerable<ttp.Models.Room> 
@{ 
ViewBag.Title = "Avail"; 
} 

<h2>Avail</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
@using (Html.BeginForm()) 
{ 
    <p> 
     Availability between @Html.TextBox("dteFrom" , String.Format("{0:dd/MM/yyyy}", DateTime.Now) , new { @class = "datepicker span2" }) 
         and @Html.TextBox("dteTo" , String.Format("{0:dd/MM/yyyy}", DateTime.Now) , new { @class = "datepicker span2" }) 
     <input type="submit" value="Search" /></p> 
} 
<table class="table table-striped table-bordered table-condensed" style="width:90%" id="indexTable" > 
<tr> 
    <th> 
     @Html.DisplayNameFor(model => model.RoomName) 
    </th> 
</tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.RoomName) 
     </td> 
... 
... 
     <td> 
      @Html.ActionLink("Book Room","Book", new { id=item.RoomId }) 
     </td> 
    </tr> 
} 

</table> 

답변

0

귀하의 의견이 강력하게 형식화 만들 ... 여기에 몇 가지 링크가 강력한 형식의 뷰 mvc.net에 알고

http://www.howmvcworks.net/OnViews/BuildingAStronglyTypedView

What is strongly-typed View in ASP.NET MVC

http://blog.stevensanderson.com/2008/02/21/aspnet-mvc-making-strongly-typed-viewpages-more-easily/

더 이상 당신이 당신의 POST 행동의 결과로 응용 프로그램에서 설정 한 기본 경로를 가지고 있다면 당신은 내가 있다는 것입니다 무엇을보고

[HttpPost] 
public ActionResult POSTACTION(int id){ 
//here you will get the room id 
} 

같은 경로 값으로하지만 코드에서 id를 얻을 수 있습니다 당신은

편집 ... actionlinks 그 경우에 GET 요청이 작업 결과에서 [HttpPost] 액션 필터를 제거 할 폼을 게시하지 않습니다

당신이

같은 지금 클릭을 첨부

@Html.ActionLink("Book Room","Book", new { id=item.RoomId },new{@class="roomclass",id=item.RoomId}) 

처럼 행동 링크에 클래스를 할당 할 수있는 옵션이 경우

내가 당신의 현재 시나리오에서 질문을 ... 오해 될 수있다 그것에 이벤트 처리기

$(function(){ 
$(".roomclass").on("click",function(e){ 
    e.preventDefault(); //prevent the default behaviour of the link 
    var $roomid = $(this).attr("id");//get the room id here 
    //now append the room id using hidden field to the form and post this form 
    //i will assume that you have only one form on the page 
    $("<input/>",{type:'hidden',name="RoomId",value:$roomid}).appendTo("form"); 
    $("form").submit(); 
    }); 
}); 

양식이 게시 될에 작업 이름과 컨트롤러를 지정

@using (Html.BeginForm("MyAction","ControllerName",FormMethod.POST)){...} 

컨트롤러에 당신은

[HttpPost] 
public ActionResult MyAction(int RoomId,DateTime? dteFrom ,DateTime? dteTo){ 
//you will get the form values here along with the room id 
// i am not sure about the type `DateTime?` parameteres if this doesn't work try using string dteFrom and string dteTo 
} 
+0

안녕 @ 존 뭔가를해야합니다 - 감사합니다 - 나는 ID에게 문제를 얻을 수 있습니다 - 나는 또한 내가 대해 확신 해요 dteFrom 및 dteTo 값을 포함하는 방법이 있습니다. 친절하게 제공 한 링크를 읽었지만 ID를 POST/GET하고 입력란에서 시작일과 종료일을 포함시키기 위해 고유 ID가있는 방을 여러 개 나열했을 때 어떻게 아직도 명확하지 않은 것입니다. .다시 한 번 감사드립니다. Mark – Mark

+0

안녕하세요 @ 존 - 아직 작동하지는 않지만 나를 가리키고있는 곳을 볼 수 있으며 80 %는 이해합니다. 내가 제안한 것을 취하고 좀 더 검색하고 나는 그것이 다음 또는 2에 걸쳐 일하게 할 것이라 확신한다. 올바른 길로 나를 데려 갈 시간을내어 주셔서 감사합니다. 정말로 감사드립니다. 건배, 마크 – Mark

+0

다행이 도울 수 ... ':)' –

관련 문제