2012-01-02 4 views
0

나는이 버튼을 통해 데이터를 ActioResult에 다시 보내고 싶다. 나는 이드와 엔티티 이름을 보내고 싶다. id는 잘 작동하지만 엔티티 이름을 보내려는 경우 작동하지 않습니다. ActionResult에 여러 변수를 다시 보내려면 어떻게해야합니까? 이것은 내 html/javascript입니다 :둘 이상의 값을 jquery로 ActionResult로 보내는 버튼이있는 방법은 무엇입니까?

@model test.Web.Framework.Areas.Administration.Models.TabNotesModel 
@using (UI.DocumentReadyScript()) 
{ 
    if (Model.meta.id.HasValue) 
    { 
     UI.jQuery("#tbl" + Model.meta.modelname).flexigrid(Model.Grid); 
     } 
    } 
<form method="post" action="@Url.Action("TabNotes", new { cmd = "refresh" })" id="@Model.meta.modelname"> 
<div class="ui-state-highlight ui-corner-all highlight" data-bind="visible: meta.message"> 
    <span class="ui-icon ui-icon-info"></span><strong data-bind="text: meta.message"> 
    </strong> 
</div> 
@using (UI.BeginBlock("Administation.TabNotes", UI.Label("Notes", "Notes").ToString(), test.Web.Framework.Core.enumIcons.pencil, false, false)) 
{ 
    <table id="@("tbl" + Model.meta.modelname)"> 
    </table> 
} 
</form> 
<script type="text/javascript"> 
(function() { 
    $('#load-partial').click(function() { 
     $('#partial').load('@Url.Action("CreateNote", "Entity", new {itemId = @Model.meta.id, modelEntity = @Model.meta.entity})'); 
// I also tried modelEntity = "Phrase" to test, but that also didn't work 
     }); 
    })(); 
</script> 

<div id="partial"></div> 
<button type="button" id="load-partial">Create Note</button> 

및 내 ActionResult입니다. modelEntity는 null로 유지됩니다. itemId가 숫자를 가져옵니다.

public ActionResult CreateNote(
     [ModelBinder(typeof(Models.JsonModelBinder))] 
     NoteModel Model, string cmd, long? itemId, string modelEntity) 
    { 

     if (cmd == "Save") 
     { 
      Model.meta.message = "Note saved"; 
      Entity entity = NotesRepository.GetEntity(modelEntity); 
      NotesRepository.StoreNote(Model.subject, Model.text, entity, itemId); 
      return RedirectToAction("TabNotes", new { modelEntity = modelEntity, id = itemId}); 
     } 

     Model.meta.modelname = "CreateNote"; 
     Model.meta.JsViewModelType = "EditNoteModel"; 
     Model.meta.PostAction = Url.Action("CreateNote", new { cmd = "Save", itemId = itemId, modelEntity = modelEntity}); 


     return PartialView("CreateNotePartial",Model); 

     } 
+2

modelEntity 자리 표시자가 포함 된 경로가 구성 되었습니까? – Sascha

답변

1

Url.Action은 경로 값만 가져 오므로 두 번째 매개 변수를 처리 할 경로가 필요합니다. 현재 경로에 itemId가 이미 있다고 가정합니다.

+0

새 변수에 대한 경로를 만들려면 어떻게해야합니까? –

+1

Global.asax에서 라우트를보아야 만합니다.'{controller}/{action}/{itemId}'와 같은 모양이 있어야합니다. - 다른 선택적 매개 변수를 추가해야합니다. 그러면'{controller}/{action}/{itemId}/{modelEntity}'컨트롤러 'Entity/CreateNote'가 두 개의 매개 변수를 얻게됩니다. –

+0

My Global.asax에는 <% @ Application Codebehind = "Global.asax.cs"만 있습니다. Inherits = "test.Web.Healthcare.MvcApplication"Language = "C#"% –

관련 문제