Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在单击按钮时渲染动态局部视图_C#_Javascript_Asp.net Mvc 3 - Fatal编程技术网

C# 在单击按钮时渲染动态局部视图

C# 在单击按钮时渲染动态局部视图,c#,javascript,asp.net-mvc-3,C#,Javascript,Asp.net Mvc 3,我在看不同的帖子,所以点击按钮我们可以做两个动作 我的aspx页面包含表单,单击按钮将表单提交给控制器,我在控制器中使用表单数据,并根据表单中的值呈现部分视图,我希望在我的aspx中显示部分视图 我正在执行以下步骤: <form id="StatsForm" name="StatsForm" action="../Stats/Index/" method="POST" enctype="multipart/form-data">

我在看不同的帖子,所以点击按钮我们可以做两个动作

我的aspx页面包含表单,单击按钮将表单提交给控制器,我在控制器中使用表单数据,并根据表单中的值呈现部分视图,我希望在我的aspx中显示部分视图

我正在执行以下步骤:

   <form id="StatsForm" name="StatsForm" action="../Stats/Index/" method="POST"
                enctype="multipart/form-data">
                <%= Html.AntiForgeryToken()%>
                <% Html.RenderPartial("OptionalFields"); %>
            </form>

 <script type="text/javascript" language="javascript">
                //<![CDATA[

                $(document).ready(function () {
                    $("#GetReport").click(function () {
                        $("form[name=StatsForm]").submit();

                    });
                });

                //]]>
            </script>
我的部分观点是:

    [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    public ActionResult InterStats(int str1Id, int str2Id, DateTime startDate, DateTime endDate)
    {
        var str = _manufacturerWidgetsRepository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId, countryId);
        var report = new ABCReport();
        var reportList = new List<ReportList>(); // a list of my anonymous type without the relationships
        report.reportList = new List<Record>();
        var count = 1;
        foreach (var mw in str)
        {
           // I am doing some function



            //  Create the data for the report
                       }
                return PartialView(report);
    }
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
公共操作结果状态间(int str1Id、int str2Id、DateTime startDate、DateTime endDate)
{
var str=\u ManufacturerWidgetsRespository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId,countryId);
var报告=新ABCReport();
var reportList=new List();//没有关系的匿名类型的列表
report.reportList=新列表();
var计数=1;
foreach(str中的var mw)
{
//我在做一些函数
//为报告创建数据
}
返回局部视图(报告);
}
我试图在我的aspx中显示我的局部视图。 我的问题是,如果不点击我的提交按钮两次,我如何向我的控制器提交表单,并将我的部分视图插入我的aspx中。

要实现这一目标,您需要做两件事:

  • 您需要控制器返回一个“PartialView”(甚至可能是一个主
    PartialView
    ,该视图委托给您在
    InterStats
    中调用的部分),而不是执行
    重定向操作
  • 您的
    .submit()
    操作需要重构,以便通过
    ajax
    提交表单,然后在成功回调中接受返回的
    ActionResult
    ,并将其附加到页面上
  • 我在运输途中,否则我可以举个简单的例子。如果仍然需要,将稍后更新

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        public ActionResult InterStats(int str1Id, int str2Id, DateTime startDate, DateTime endDate)
        {
            var str = _manufacturerWidgetsRepository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId, countryId);
            var report = new ABCReport();
            var reportList = new List<ReportList>(); // a list of my anonymous type without the relationships
            report.reportList = new List<Record>();
            var count = 1;
            foreach (var mw in str)
            {
               // I am doing some function
    
    
    
                //  Create the data for the report
                           }
                    return PartialView(report);
        }