I use an autocomplete to introduce the description of a product and get the ProductID and the Price with a javascript function:
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$("#Description").change(function () {
$("#ProductID").val(Description_autocomplete_hidden.value);
$("#Price").load('@Url.Action("GetPrice", "Product")', { id: parseInt($("#ProductID").val()) });
});
});
});
</script>
The ProductID works fine, the action, e.g., “\Product\GetPrice\4” is correctly called but I am unable to assign the product price to the $(“#Price”).
The razor code:
<div class="row">
<div class="label">@Html.Label("Product")</div>
<div class="input">@Html.AutoComplete("Description","","Product","_Shared")</div>
</div>
<div id ="ProductID"></div>
<br />
<div class="row">
<div class="label">@Html.Label("Price")</div>
<div class="input">@Html.Editor("Price")</div>
</div>
The GetPrice() in the Product controller:
public string GetPrice(int id)
{
return unitOfWork.ProductRepository.GetByID(id).Pvp1.ToString();
}