2012-01-02 92 views
0

我有这个按钮,我想要将数据发送回ActioResult。我想发送和id和实体名称。该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保留为空。 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 2012-01-02 15:16:24

回答

1

Url.Action只接受路由值,所以你认为你需要一个路由来处理第二个参数。我假设你的当前路线已经有了itemId,这就是它工作的原因。

+0

如何为新变量创建路线? – 2012-01-02 15:34:05

+1

在Global.asax中,你应该看到你的路线,你应该看到一个看起来像是“{controller}/{action}/{itemId}”的 - 你需要为此添加另一个可选参数,因此它看起来像是{controller}/{action}/{itemId}/{modelEntity}'这样控制器'Entity/CreateNote'将获得两个参数。 – 2012-01-02 15:50:05

+0

我的Global.asax只有<%@ Application Codebehind =“Global.asax.cs”Inherits =“test.Web.Healthcare.MvcApplication”Language =“C#”%> – 2012-01-02 16:01:59

相关问题