As I work on constructing a website using MVC 3 razor, there is a specific scenario that I am currently dealing with:
- One of the challenges involves a controller method:
public ActionResult MyControllerMethod(int parameter){
''perform some database operations
IList<My_Custom> datafromDB = MyService.GetData(parameter);
'return data to my strong-typed view
return View(datafromDB);
}
- Furthermore, in the situation outlined above, there is a strong-typed view where JavaScript plays a crucial role:
@model IList<My_Custom>
<script type="text/javascript">
function getData()
{
var parameter = document.getElementById('myParamater').value;
$.get('/MyController/MyControllerMethod/' + parameter, function (data) {
loadData();
}
);
}
function loadData()
{
clearData();
datos = @Html.Raw(Json.Encode(Model));
//manipulate datos as needed
}
</script>
While the JavaScript call to the controller is functioning properly, I have encountered an issue regarding the strong-typed view not updating the @model's value accordingly. As a result, it continues to display the same information.
Despite debugging the action controller and confirming that it indeed returns varied data each time, I have yet to find a way to refresh the Model value within the strong-typed view.
I attempted to manipulate the data value from this line of code:
$.get('/MyController/MyControllerMethod/' + parameter, function (data) {
However, my attempts at doing so proved to be unsuccessful.