Javascript ajax成功时未显示HTML按钮

Javascript ajax成功时未显示HTML按钮,javascript,jquery,ajax,asp.net-mvc-3,razor,Javascript,Jquery,Ajax,Asp.net Mvc 3,Razor,我需要在我的视图中的成功消息上显示一个输入按钮。我在使用razor视图的MVC3应用程序中工作。此按钮将允许用户导航到其他视图 控制器。 JavaScript。 看法 请告知。是的,您可以在ajax调用中生成html,如下所示: <div id="div1"><div> success: function (result) { // clear table $('#instruments-data').em

我需要在我的视图中的成功消息上显示一个输入按钮。我在使用razor视图的MVC3应用程序中工作。此按钮将允许用户导航到其他视图

控制器。 JavaScript。 看法
请告知。

是的,您可以在ajax调用中生成html,如下所示:

<div id="div1"><div>

success: function (result) {
                // clear table
                $('#instruments-data').empty();
                resultMessage(result);
                $('#div1').html('<input type="button" class="styledbutton" value="Some text" onclick="window.location.href='@Url.Action("actionName", "controllerName")'/>')
            }

上面的代码可以正常工作,只需像上面那样在ajax调用中生成html。

按钮是静态的,因此您可以隐藏它

<input style="display:none" type="button" class="styledbutton" value="Some text" onclick="window.location.href='Url.Action("actionName", "controllerName")';" />

你可以用一种简单的方法来做。正如我们所建议的,最初可以使用css隐藏按钮


注意:将按钮准确放置在视图中希望看到的位置,并使其显示:无。Ajax将处理其余的问题。如果它不起作用,请告诉我。

之前的答案都不允许重新定向,因此我找到了解决方法

  success: function (result) {
                // clear table
                $('#instruments-data').empty();
                resultMessage(result);
                $('#resultMessage').append('<input type="button" id="MultiStatus"class="styledbutton" value="Button text" />');
                $('#MultiStatus').click(function (e) {
                    location.href = "/Controller/Action";
                });

如果您需要建议,我建议您尝试使用引导样式的锚按钮,以反映按钮的感觉

如果这不影响你的意图,你能试试这个吗

例如:

@Html.ActionLink("ButtonText", "ActionName", "ControllerName", null, new { @id = "Query", @class = "btn btn-inverse styledButton" })
我提供了一个jsbin演示,介绍如何根据您的具体需要使用按钮,请点击以下链接:


如果您需要任何解释,请随时发表评论。

以上内容。。。甚至把警报放在前面,警报已经到达,但按钮没有显示?必须使用Id,因为视图中有其他具有相同类的btnd。我在需要的地方包括了上面的引号和闭引号…$'div1'.html。。。。它没有击中我放在它前面的警报,我在@Url下有绿色线条-条件复杂性被关闭,在“/>”下-预期,或任何想法?不,它完全跳过成功函数。没有mgs显示,数据不会保存到db EIT当然,这毕竟是ajax。好消息是,它按原样将数据保存到数据库中-坏消息没有显示按钮,此语法肯定有问题,方法很简单-onclick=window.location.href='Url.ActionactionName,controllerName';,由于输入没有显示它…也请不要,我必须使用id=demo和$'demo',因为我有相同类的其他btn。id的名称不重要,它取决于你选择什么。我只是做了示范。Beisdes尝试通过访问ID来显示按钮,尽管这不会有任何区别。您是否将输入按钮置于页面上,使其显示为:无??
        onclick="window.location.href = '@Url.Action("actionName", "controllerName")'"/>');
<div id="div1"><div>

success: function (result) {
                // clear table
                $('#instruments-data').empty();
                resultMessage(result);
                $('#div1').html('<input type="button" class="styledbutton" value="Some text" onclick="window.location.href='@Url.Action("actionName", "controllerName")'/>')
            }
<input style="display:none" type="button" class="styledbutton" value="Some text" onclick="window.location.href='Url.Action("actionName", "controllerName")';" />
            success: function (result) {
            // clear table
            $('#instruments-data').empty();
            resultMessage(result);
            //show button
            $(".styledbutton").show();
        },
<input type="button" class="styledbutton" style="display:none;" value="demo" onclick="window.location.href='Url.Action("actionName", "controllerName")';"/>
$.ajax({
   url: '/Builder/CreateWork',
   type: 'POST',
   dataType: 'json',
   data: jsonText,
   contentType: 'application/json; charset=utf-8'
 }).done(function(result){
     // clear table
     $('#instruments-data').empty();
     resultMessage(result);
     //just show the button
     $(".styledbutton").show();
 }).always(function(){
     // hides the loading gif
     $('.loading').hide();
});
  success: function (result) {
                // clear table
                $('#instruments-data').empty();
                resultMessage(result);
                $('#resultMessage').append('<input type="button" id="MultiStatus"class="styledbutton" value="Button text" />');
                $('#MultiStatus').click(function (e) {
                    location.href = "/Controller/Action";
                });
@Html.ActionLink("ButtonText", "ActionName", "ControllerName", null, new { @id = "Query", @class = "btn btn-inverse styledButton" })