2013-05-20 71 views
0

我對MVC非常陌生,並且對新手有關MVC的知識。
我正在創建一個MVC應用程序,我有這個頁面顯示在特定時間發生的事件。 現在,當我從下拉列表中選擇事件時,我會得到具體事件的詳細信息。現在,隨着該特定事件的描述,我需要獲得人們爲特定事件輸入的反饋。
這是我的觀點:傳遞Html.ActionLink中的值

<div><a href="<%:Url.Action("ManagementHome","Home")%>">Home </a>>> Events</div> 
<br /> 
<%:Html.LabelFor(m => m.Event)%> 
<%:Html.DropDownListFor(m => m.Event.SelectedValue, Model.Event.GetSelectList(), new { id = "EventDropDown"})%> 
<br /><br /> 
<div id="result" style="color: Green; border: 1px null transparent; "> 
<%Html.RenderPartial("~/Views/PartialViews/EventsPartial.ascx"); %> 
</div> 
<%:Ajax.ActionLink("view", "viewFeedback", "Home", new AjaxOptions { UpdateTargetId = "comments" }, new {eventid=Model.Event.SelectedValue})%> 

<div id="comments" style="color: Green; border: 1px null transparent;"> 
<%Html.RenderPartial("~/Views/PartialViews/FeedbackPartial.ascx"); %> 
</div> 

任何人都可以請建議我如何通過該事件的ID在其ActionLink的? 在此先感謝

回答

0

u必須使用AJAX功能如下:

$('youractionlinkid').click(function() { 
      var id = $('#yourdropdownid').val(); 
     $.ajax({ 
      url: this.href, 
      type: 'GET', 
      data: { id:id }, 
      cache: false, 
      success: function (result) { 
       //do some action here 
      } 
     }); 
     return false; 
    }); 
2

您可以使用routeValues在參數中傳遞值Html.ActionLink

例如:

// VB 
@Html.ActionLink("Link Text", "MyAction", New With {.eventId = 1}) 

// C# 
@Html.ActionLink("Link Text", "MyAction", new {eventId = 1}) 

可能會產生鏈接:

http://localhost/MyAction?eventId=1 
+0

但是這將是硬編碼。 我們可以得到類似的東西 - 當我們從下拉菜單中選擇數值時,它會自動使用'eventId'嗎? – Novice

+0

絕對,但沒有看到你的代碼,我不能爲你編程。 –

+0

我已經發布了我的視圖的代碼,我正在嘗試做什麼。請建議我如何將我的下拉選定值綁定到html.actionink .. – Novice

0

剃刀將AJAX這種方式也:

<div class="editorholder"> 
    @Html.DropDownListFor(model => model.Display_ID, new SelectList(Model._listAllDisplayViewModel.ListAllDisplayInfo, "DisplayID", "DisplayName"), "Select.....", new { @class = "form-control", @id = "DisplayID", @onchange = "DisplayInfo();" }) 
</div> 




<div class="editor-field"> 
    <div id="DisplayView"> 
    @Html.Partial("_DisplayView", Model._displayViewModel) 
    </div> 
</div> 




function DisplayInfo() { 
    $("#DisplayView").load('@(Url.Action("_DisplayView", "Display", null, Request.Url.Scheme))?id=' + $("#DisplayID").val()); 
}; 
相關問題