且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发送局部视图模型和更新局部视图使用jQuery有问题

更新时间:2023-12-02 18:07:22

我找到了。感谢来自@大卫的第一个问题。我分开,与变量名指出职能下放事件的内部行为和部分与返回的结果更新HTML后附加事件委托给他们。这是一个简单的例子:

I found it. Thanks from @David for first issue. I separate internal actions of delegated events to functions that pointed with variable names and attach delegate events to them after update html of partial with returned result. this is a simple sample:

var sampleHandler = function() { //some code }

,然后在阿贾克斯成功:

and then in ajax success:

success: function (sucResult) {
         $('#pa_Cnt').html(sucResult);
         $("[parentClassNameSelector]").on("click", '[childSelector]', sampleHandler);
   }



关于MVC的第二个问题的ModelState是有罪的。 :)特别是在通过MVC佣工渲染的元素。于是我决定这样做的控制器动作

About second issue ModelState of MVC is Guilty. :) specially in elements that rendered by mvc helpers. So i decide to do this in controller action.

if (ModelState.IsValid) { ModelState.Clear(); }



我不知道这是好或者有其他问题。现在它是解决我的问题。我在等待新的意见和建议。非常感谢。

I don't know if this is good or has any other issue. For now it was solved my problem. I'm waiting for new comments and advises. Thanks so much.