I used mvc partial control on my page twice for the search function. It has its own controller for searching, so on my page there are two controllers with the same name.
<div ng-app="app" ng-controller="MainController" ng-init="SetSearchParam()"> <div id="search1"> @Html.Partial("_SearchPartial") // say it search1 // some other code to show search results // .... // .. </div> <div id="search2"> @Html.Partial("_SearchPartial") // say it search2 // some other code to show search results // .... // .. </div> </div>
This is _SearchPartial:
<form name="SearchCommon"> <div ng-model="search" ng-controller="SearchPartialController"> <div> <input type="text" value="" placeholder="Stock" ng-model="search.Stock" /> </div> <div> <input type="text" value="" placeholder="Make" ng-model="search.Make" /> </div> <div> <input type="text" value="" placeholder="Year" ng-model="search.Year" /> </div> <div> <input type="submit" value="SEARCH" ng-click="searchdata(search)" /> </div> </div> </form>
Now that init MainController , I set the value of the search model in the SetSearchParam() method, as shown below:
$scope.SetSearchParam = function(){ var s = {}; s.Make = "Test"; s.Year = "2012"; s.Stock = "5" $scope.search = s; };
The search model is used as search , and the page has two search controls, the value of the s parameter will be set as in the partial controller. Also, when I change the parameters in search1, it will display search2.
I want these search options to be set only for search1 and not for search2. When I change the search1 parameters, it should not reflect search2 or vice versa.
Is there any way to achieve this?
source share