实际上,每当我搜索时,我都会尝试更新部分视图内容。所以我使用ajax调用来实现这一点。因此,从控制器到局部视图模型的值是正确的(新数据),但它不绑定到视图(显示现有数据)。
主视图
import React, {Component} from 'react';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware, compose} from 'redux';
import {PersistGate} from 'redux-persist/lib/integration/react';
import {persistStore, persistReducer} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import Thunk from 'redux-thunk';
import Router from './Router';
import reducers from './reducers';
const persistConfig = {
key: 'root',
storage: storage,
};
const persistedReducer = persistReducer(persistConfig, reducers);
const store = compose(persistedReducer, {}, composeEnhancers(applyMiddleware(Thunk)));
class App extends Component {
render() {
const persistor = persistStore(store);
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<Router />
</PersistGate>
</Provider>
);
}
}
export default App;
部分视图(_详细信息)
<div class="tab-pane active" id="partialviewpage">
@{
Html.RenderPartial("_Details", Model);
}
</div>
Ajax Call
foreach (var item in Model.AllAds)
{
//div contents
}
类别控制器
var text = 'test';
$.ajax({
url: '@Url.Action("Subcategory", "Category")',
type: 'GET',
dataType: 'JSON',
data: { item: text },
success: function (partialView) {
$('#partialviewpage').html(partialView);
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
那么,我的代码有什么问题,我如何修改代码以获得新的模型值。任何帮助赞赏。提前谢谢。
答案 0 :(得分:0)
我发现您使用了错误的变量来成功替换html,
我已将{{1}}替换为{{1}}
{{1}}