我有這個按鈕,我想要將數據發送回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);
}
您是否配置了路由,其中包含modelEntity佔位符? – Sascha 2012-01-02 15:16:24