Click here to Skip to main content
16,006,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Frnds,
I am facing problem when I am going to pass ng-model value (Ex
HTML
Date
-25-04-2016) as parameter to
HTML
@Html.ActionLink
.

HTML
<div class="col-md-2">
                <label>Start Date &nbsp;</label>
                <input type="text" ng-model="startdate" class="form-control disable-date-control" name="startdate" />
            </div>


Code :- @Html.ActionLink("Time Sheet", "Index", "Timesheet", new { date = startdate},null).

When I select the start Date, I want pass
HTML
<b>start Date</b>
as parameter to @Html.ActionLink.

What I have tried:

@Html.ActionLink("Time Sheet", "Index", "Timesheet", new { date = ((DateTime)ViewBag.timesheetDate).ToString("dd-MM-yyyy") },null)
Posted
Updated 2-Aug-16 4:18am

1 solution

try using Angular Watch[^]

refer this

HTML
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="~/Scripts/jquery-1.8.2.js"></script>

 <div ng-app="myApp" ng-controller="myCtrl">

     <input type="text" ng-model="startdate" class="form-control disable-date-control" name="startdate" />
    @Html.ActionLink("Link name", "index", "Home", new { Date = "" }, new { id = "myLinkId" });
     {{startdate}}
    </div>


    <script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function ($scope) {
            $scope.startdate = "08/02/2016";

            $scope.$watch('startdate', function (newValue, oldValue) {
                var href = $('#myLinkId').attr('href');
                href = href.split('?Date')[0] + '?Date=' + newValue
                $('#myLinkId').attr('href', href);
                 
            });
        });
       
    </script>
 
Share this answer
 
v2
Comments
rameshvar 3-Aug-16 2:41am    
Hii Karthik,
I used above code but. I am getting error in app.js file.
Error - href is undefined.
Karthik_Mahalingam 3-Aug-16 2:48am    
try this alone in a separate page.
show your code.
rameshvar 3-Aug-16 3:03am    
$scope.$watch('startdate', function (newValue) {
var href = $('#myLinkId').attr('href');
href = href.split('?date')[0] + '?date=' + newValue
$('#myLinkId').attr('href', href);
});
Karthik_Mahalingam 3-Aug-16 3:05am    
make sure the Actionlink has id like

@Html.ActionLink("Link name", "index", "Home", new { Date = "" }, new { id = "myLinkId" });

going for lunch, wil be back in few mins
rameshvar 3-Aug-16 3:07am    
yes same as above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900