You haven't call the function accordingly. You are expecting your PassToContoller function should invoke while you click on save in your case either you have to call this function with btnSave onlick or onClick="PassToContoller(@item.Name)"
I am showing you both here:
When onClick="PassToContoller(@item.Name)" In Line:
Razor HTML
<div class="container">
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4">
<div class="card" style="width: 18rem;">
@*<img src="~/Content/no_foto.png" class="card-img-top" alt="...">*@
<div class="card-body">
<h5 class="card-title">@item.Name</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div id="textButton">
<a href="~/TrainingType/ListCoach" id="btnSave" class="btn btn-primary">Go to anywhere</a>
<a id="btnSave" class="btn btn-primary">Go to anywhere</a>
<input class="btn btn-primary" type="button" id="btnSave" onClick="PassToContoller(@item.Name)" value="Save" />
</div>
</div>
</div>
</div>
}
</div>
</div>
Script:
<script>
function PassToContoller(data) {
alert(data);
$.ajax({
type: "GET",
url: '/ListCoachController/ListCoach',
data: { id: data },
success: function (data) {
console.log(data);
window.location.href = '/appUser/ManageAccount';
return data;
},
error: function () {
$("#loader").fadeOut("slow");
console.log("error1");
}
});
}
</script>
Output:

Aother way btnSave Onlick:
In this you need few modifications:
Need to introduce a input type text which will be hidden it will
contrain a value like this <input type="text" id="getValue" value="@item.Name" hidden /> and will pass that hidden value when you
would click the button.
Another thing is your btnSave seems you have used same for other button as well so your onclick function will getConfused which event to fired. So need to set unique btn id Now rest of the same like below:
Razor HTML
<div class="container">
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4">
<div class="card" style="width: 18rem;">
@*<img src="~/Content/no_foto.png" class="card-img-top" alt="...">*@
<div class="card-body">
<h5 class="card-title">@item.Name</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div id="textButton">
<a href="~/TrainingType/ListCoach" id="btnSave" class="btn btn-primary">Go to anywhere</a>
<a id="btnSave" class="btn btn-primary">Go to anywhere</a>
<input class="btn btn-primary" type="button" id="btnNewSave" value="Save" />
<input type="text" id="getValue" value="@item.Name" hidden />
</div>
</div>
</div>
</div>
}
</div>
</div>
Script:
@section scripts {
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function () {
$("#btnNewSave").click(function () {
var data = $("#getValue").val();
$.ajax({
type: "GET",
url: '/ListCoachController/AnotherListCoach',
data: { id: data },
success: function (data) {
console.log(data);
window.location.href = '/appUser/ManageAccount';
return data;
},
error: function () {
$("#loader").fadeOut("slow");
console.log("error1");
}
});
});
});
</script>
}
Update:
Based on your new requirement on comment you just need to update your HTML like below:
<div class="container">
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4">
<div class="card" style="width: 18rem;">
@*<img src="~/Content/no_foto.png" class="card-img-top" alt="...">*@
<div class="card-body">
<h5 class="card-title">@item.Name</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div id="textButton">
<a href="~/TrainingType/ListCoach" class="btn btn-primary" onClick="PassToContoller(@item.Name)">Go to anywhere</a>
<a class="btn btn-primary" onClick="PassToContoller(@item.Name)">Go to anywhere</a>
<input class="btn btn-primary" type="button" onClick="PassToContoller(@item.Name)" value="Save" />
<input type="text" id="getValue" value="@item.Name" hidden />
</div>
</div>
</div>
</div>
}
</div>
</div>
Note: You have to get rid of id="btnSave" from all the <a> and <button> and need to replace with
onClick="PassToContoller(@item.Name)" it will pass all of your
value. No matter how many cycle you have.
Update with Comment Can I do without?:
HTML:
<div class="container">
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4">
<div class="card" style="width: 18rem;">
@*<img src="~/Content/no_foto.png" class="card-img-top" alt="...">*@
<div class="card-body">
<h5 class="card-title">@item.Name</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div id="textButton">
<a href="#" class="btn btn-primary" >Go to anywhere</a>
<a class="btn btn-primary">Go to anywhere</a>
<input class="btn btn-primary" type="button" value="Save" />
<input type="text" id="getValue" value="@item.Name" hidden />
</div>
</div>
</div>
</div>
}
</div>
</div>
Script:
@section scripts {
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script>
function PassToContoller(data) {
alert(data);
$.ajax({
type: "GET",
url: '/UserLog/AnotherListCoach',
data: { id: data },
success: function (data) {
console.log(data);
window.location.href = '/appUser/ManageAccount';
return data;
},
error: function () {
$("#loader").fadeOut("slow");
console.log("error1");
}
});
}
$(document).ready(function () {
$("a").click(function () {
var data = $("#getValue").val();
var callFunc = PassToContoller(data)
});
$(":button").click(function () {
var data = $("#getValue").val();
var callFunc = PassToContoller(data)
});
});
</script>
}
Hope it would guide you accordingly. You can used either of the approach.
Trainingclass defination. So that it can be reporduce accordingly.Update with Comment Can I do without?part which has the solution of your last comment. Every way has been shown now it's your choice which one you would implement.