首页 \ 问答 \ 每当调用PartialView时,确保视图控制器方法获取最新的图表数据(Ensuring view controller method to get latest chart data is called whenever PartialView called)

每当调用PartialView时,确保视图控制器方法获取最新的图表数据(Ensuring view controller method to get latest chart data is called whenever PartialView called)

我在Web.Helpers中使用Chart来呈现视图的图形。 这个视图的数据集可以通过类型区分为子集,并且该视图允许用户选择类型。

包含此图表的我的剃须刀视图(_Chart.schtml)很简单:

<p>
<img src="/MyController/MyChart" />
</p>

控制器代码(简化)

public void MyChart()
{
  ChartSeries[] data = GetChartData(new string[] { _curChartDataType });
var chart =
                new Chart(500, 200, ChartTheme.Green);

                    for (int i=0; i<data.Length; i++) {
                        title += data[i].name + " ";
                        chart.AddSeries(name: data[i].name, chartType: "Line",                                                       
                           xValue: data[i].xValue, xField: data[i].xField,                
                           yValues: data[i].yValues, yFields: data[i].yFields);   
                    }
                    chart.AddTitle(title)
                    .AddLegend()
                    .Write("png");
}


public ActionResult ObjectList()
 {
            // irrelevant code removed

            return PartialView("_Chart");
}

在父视图的cshtml中,我使用jquery来捕获用户对类型选择的更改,并调用ajax中的MyController / ObjectList调用。

第一次加载视图时,图形正确呈现。 但是,用户调用的类型更改会导致后续对ObjectList的调用(如预期的那样),但MyChart()在第一次后再也不会被调用。

任何我应该做的事情来确保MyChart()每次调用PartialView(“_ Chart”)时都会被调用? 任何建议感激。


I am using Chart in Web.Helpers to render graphs for a view. The data set for this view can be distinguished by type into subsets, and the view allows the user to select a type.

My razor view containing this graph (_Chart.schtml) is simply:

<p>
<img src="/MyController/MyChart" />
</p>

The controller code (simplified)

public void MyChart()
{
  ChartSeries[] data = GetChartData(new string[] { _curChartDataType });
var chart =
                new Chart(500, 200, ChartTheme.Green);

                    for (int i=0; i<data.Length; i++) {
                        title += data[i].name + " ";
                        chart.AddSeries(name: data[i].name, chartType: "Line",                                                       
                           xValue: data[i].xValue, xField: data[i].xField,                
                           yValues: data[i].yValues, yFields: data[i].yFields);   
                    }
                    chart.AddTitle(title)
                    .AddLegend()
                    .Write("png");
}


public ActionResult ObjectList()
 {
            // irrelevant code removed

            return PartialView("_Chart");
}

In the parent view's cshtml, I use jquery to catch the user's change in type selection and invoke the call to MyController/ObjectList in ajax.

The graph renders properly when the view is first loaded. However, the user-invoked type changes result in a subsequent call to ObjectList (as expected), but MyChart() never gets called again after the first time.

Anything I should do to ensure MyChart() gets called again whenever PartialView("_Chart") is called? Any suggestions appreciated.


原文:https://stackoverflow.com/questions/36848191
更新时间:2021-08-28 11:08

最满意答案

这是一个特别模糊的功能吗?

是的,转换运营商不常使用。 我见过的地方是用户定义的类型,可以降级为内置类型。 像支持从原子数类型转换到/从原子数类型的固定精度数字类。

这是相对便携吗?

据我所知,它是。 他们永远处于标准之中。

用户定义的转换可以完成用户定义的类型吗?

是的,这是构造函数的特点之一。 一个构造函数能够有效地创建一个从参数类型到类的类型的转换运算符。 例如,像这样的一个类:

class Foo {
public:
    Foo(int n) {
        // do stuff...
    }
}

让你做:

Foo f = 123;

如果你之前使用过std::string ,那么你已经使用了这个特性而没有意识到它。 (顺便说一句,如果要防止这种行为,请使用explicit声明任何单参数构造explicit 。)


Is this a particularly obscure feature?

Yes, conversion operators aren't used very often. The places I've seen them are for user-defined types that can degrade to built-in ones. Things like a fixed-precision number class that supports converting to/from atomic number types.

Is this relatively portable?

As far as I know, it is. They've been in the standard forever.

Can user-defined conversions to user defined types be done?

Yes, that's one of the features of constructors. A constructor that takes a single argument effectively creates a conversion operator from the argument type to your class's type. For example, a class like this:

class Foo {
public:
    Foo(int n) {
        // do stuff...
    }
}

Let's you do:

Foo f = 123;

If you've used std::string before, odds are you've used this feature without realizing it. (As an aside, if you want to prevent this behavior, declare any single-argument constructors using explicit.)

相关问答

更多
  • 当您的类的实例位于添加的右侧时,您需要实现__radd__方法来处理这种情况。 文档说: 调用这些方法来实现二进制算术运算(+, - ,*,@,/,//,%,divmod(),pow(),**,<<,>>,&,^,|)反映(交换)的操作数。 这些函数仅在左操作数不支持相应操作且操作数具有不同类型时才会调用。 2例如,要评估表达式x-y,其中y是具有rsub ()方法的类的实例,y。 如果是x,则调用rsub (x)。 sub (y)返回NotImplemented。 例: class tInt(int): ...
  • 这是一个特别模糊的功能吗? 是的,转换运营商不常使用。 我见过的地方是用户定义的类型,可以降级为内置类型。 像支持从原子数类型转换到/从原子数类型的固定精度数字类。 这是相对便携吗? 据我所知,它是。 他们永远处于标准之中。 用户定义的转换可以完成用户定义的类型吗? 是的,这是构造函数的特点之一。 一个构造函数能够有效地创建一个从参数类型到类的类型的转换运算符。 例如,像这样的一个类: class Foo { public: Foo(int n) { // do stuff... ...
  • 您希望让用户为您命名,并能够将其与向量相关联吗? 这就是std::map的用途, std::string作为键类型, std::vector作为有效负载类型。 You want to have users give you a name and to be able to associate that with a vector of things? That's what a std::map is for, with a std::string as the key type and a std::ve ...
  • 没有涉及引用的标准转换,因此此规则不相关。 相反,我们需要初始化引用的规则,在C ++ 11 8.5.3中给出。 这些都很复杂; 这里的相关内容是第5条的最后一个子弹(对于初始化程序与引用类型不是引用兼容的情况): 使用非参考拷贝初始化的规则,从初始化表达式创建并初始化类型为cv1 T1的临时类型 这里, cv1 T1是const CL1 。 无法从int创建临时T1 ,因此初始化失败。 编译器不需要搜索从引用类型派生或可转换为引用类型的所有类型; 它只考虑引用类型本身。 您必须指定要创建CL2 : fun ...
  • 您在两个类中都定义了Alpha(Beta x) ,因此应该使用哪个是模糊的。 允许每个类仅处理转换为自身。 换句话说, struct Alpha实现了Alpha(Beta b)因为它最好知道如何创建自己的实例。 另外,我会考虑实现显式转换而不是隐式转换。 它有时可能会意外地导致错误或意外转换,并且在处理复杂类时通常会进行“有损”转换。 public struct Alpha { internal string value; public static implicit operator A ...
  • 在您的代码中,用户定义类型和基本类型之间的处理没有区别。 这两行的行为有什么不同: foo(a); foo(3.3); 是a是左值, 3.3是右值。 rvalue参数匹配您的重载1 (仅接受rvalues),而lvalue参数不匹配。 如果您尝试使用rvalue参数调用foo ,它也将匹配1并失败,例如foo(A{}); 。 In your code, there is no difference in treatment between user-defined types and primiti ...
  • 你需要的是显式构造函数: struct I { explicit I( V& v ){} }; struct CI { explicit CI( const V& v ){} //I would like to say const only }; 太多的C ++程序员忽略了构造函数的显式关键字。 默认情况下,所有一元参数化构造函数都应该是显式的。 隐式构造函数会引发像这样的歧义问题,并导致非常愚蠢,迂回的转换过程,这些过程很容易导致代码有问题且效率低下。 现在你已经设置好了,歧义问题 ...
  • 让我们首先看看当我们遵循各种规则时会发生什么。 遵循C#4.0规范中的规则: 搜索用户定义转换的类型集D由A和B组成。 适用转换的集合U包括用户定义的从A到B的隐式转换,以及从A提升的用户定义隐式转换? 到B? 我们现在必须选择U这两个元素中最独特的一个。 最具体的来源类型是A?。 最具体的目标类型是B. 你不包含A的任何转换? 到B,所以这是模棱两可的。 这应该是有道理的。 我们在这里不知道转换是否应该使用提升转换,从A转换? 到B? 然后从B? 到B,或者我们是否应该使用未提升的转换,从A转换? 到A然 ...
  • 这是标准Stack类的扩展方法(你可以稍微重写一下,并在你自己的Stack类中使用类似的实例方法): public static class MyStackExtensions { public static Stack Convert( this Stack stack, Func converter = null) { if (stack == null) ...
  • 成员比较运算符不允许在左侧进行隐式转换,您需要使运算符成为非成员函数: class Complex { public: int data; Complex(int i) : data(i) {} }; bool operator < (const Complex& lhs, const Complex& rhs) { return lhs.data < rhs.data; } 现场演示 Member comparison operators do not allow for implic ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)