Sorry, I am assuming that this is trival question, but I want to perform the same action as would be performed by Html.ActionLink(), but performed programmatically (without user selecting the link) within the view.
The goal is to call the view's controller/action to fully re-render this view with new information.
jeff00seattl...
Member
44 Points
112 Posts
MVC3 Razor - Html control can programmatically perform Html.ActionLink()?
May 09, 2012 06:54 PM|LINK
Hi
Sorry, I am assuming that this is trival question, but I want to perform the same action as would be performed by Html.ActionLink(), but performed programmatically (without user selecting the link) within the view.
The goal is to call the view's controller/action to fully re-render this view with new information.
Thanks
Jeff in Seattle
ignatandrei
All-Star
134913 Points
21619 Posts
Moderator
MVP
Re: MVC3 Razor - Html control can programmatically perform Html.ActionLink()?
May 09, 2012 07:05 PM|LINK
http://bit.ly/mvc_ajax_jquery
jeff00seattl...
Member
44 Points
112 Posts
Re: MVC3 Razor - Html control can programmatically perform Html.ActionLink()?
May 09, 2012 09:09 PM|LINK
thanks for the reply
I looked at the article and I tried the following, but the expected action is not getting called.
I want the following action to get called
public partial class SendCardController : Controller { [HttpGet] public ActionResult GetDigitalPreview(DigitalPreviewModel model) { /***/ } }And within the view I have injected the following ajax javascript, but it is not connecting with the expected controller/action:
@if (grid.HasSelection) { Model.Selected = grid.SelectedRow.Value; <script type="text/javascript"> var actionUrl = Html.Raw(Json.Encode(Url.Action("GetDigitalPreview", "SendCard"))); $.ajax({ url: actionUrl, type: 'GET', cache: false, data: { model: Model } }); </script> }What am I missing?
Thanks
Jeff in Seattle
ignatandrei
All-Star
134913 Points
21619 Posts
Moderator
MVP
Re: MVC3 Razor - Html control can programmatically perform Html.ActionLink()?
May 10, 2012 03:25 AM|LINK
A lot:
1. Do not call a GET method - call a POST method. It's easier in MVC.
2. Make a simplest code in the public ActionResult GetDigitalPreview and show us
3. Instead of
put
var actionUrl = '@Url.Action("GetDigitalPreview", "SendCard")';
4.
See how I create the Model to be send in the
functionsaveEmployeefrom javascript.
5.Please try to reproduce my example first and then make yours.