如何使用 jquery 将多个值发送回 ActionResult 的按钮?

发布于 2024-12-24 23:57:06 字数 2299 浏览 1 评论 0原文

我有这个按钮,我想用它将数据发送回 ActioResult。我想发送 id 和实体名称。 id 工作正常,但当我也想发送实体名称时,它不起作用。如何将多个变量发送回 ActionResult?这是我的 html/javascript:

@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);

        }

I have this button with which I want to send data back to the ActioResult. I want to send and id and an entity name. The id works fine, but when I also want to send the entity name it does not work. How do I send back multiple variables to the ActionResult? This is my html/javascript:

@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>

and my ActionResult. The modelEntity stays null. The itemId does get the number.

   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);

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-12-31 23:57:06

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

Url.Action only takes route values there, so you I think you need a route to cope with the second parameter. I assume your current route already has itemId which is why it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文