1

我正在尝试从部分视图中仅更新部分页面。如果我使用它,它工作得很好

<a href="" data-ajax-met data-ajax="true" data-ajax-url="/Index?Handler=Partial" data-ajax-update="#panel">Click heeeeeeeere</a>

但这是一个简单的获取,我想实际发布一些数据并用它做一些事情。我写了一个表单,将它的方法设置为像这样发布。

<form method="post" data-ajax="true" data-ajax-method="post" data-ajax-complete="completed" data-ajax-update="#panel" >
    <div class="row">
        id : @Html.TextBoxFor(x => x.customer.ID)
    </div>
    <div class="row">
        Name : @Html.TextBoxFor(x => x.customer.Name)
    </div>

    <div class="row">
        <input type="submit" value="send data" />
    </div>
</form>

但是这会更新我的整个页面,所以我的整个页面只是应该更新的部分视图。

4

1 回答 1

1

第一次观察,您似乎缺少第二种形式的 data-ajax-url 。话虽如此,那么在您的 Razor 视图中,您应该包括在页面顶部

@page "{handler?}"

这将允许您将其他信息传递给您的处理程序,然后在您的表单中您可以简单地包含类似

<input type="hidden" name="id" value="send value"/>

其中 value 是您要传递的值, name 是处理程序如何识别将其绑定到的属性,然后在您的 .cshtml.cs 页面中,您的处理程序应该看起来像这样

public IActionResult OnPostPartial(string id) {...//do something here id == "send value"}

希望这可以帮助

于 2019-08-06T12:13:56.940 回答