I am working on an ASP.NET MVC4 application and I have this problem. I have an @Url.Action() defined like so:
<a href="@Url.Action("Edit",
new { docId = Model.Page.Documents[j].DocumentID,
PageID = Model.Page.PageID,
docName = Model.Page.Documents[j].Name })" >Edit</a>
But as the name says this is supposed to send data which has been edited to a controller action where I will actually perform Update for this entity. docId and PageID are DB ID's which I take from the model and I need them to identify the right entity that I should apply the changes to, so they are static. However docName is a value rendered like :
@Html.TextBoxFor(m => m.Page.Documents[j].Name, new { id = Model.Page.Documents[j].DocumentID})
so the text inside this textbox could be edited and when the link with @Url.Action("Edit"..) is clicked I want to take the current value of the textbox and send it back to server.
You can see above how I am using the @url.Action("Edit"..) but logically :
docName = Model.Page.Documents[j].Name
keeps the initial value passed from the server and not the current value of the textbox. I couldn't think of more MVC4-like way to send the data to my controller so I resort to the fact that I'll need to use JavaScript(preferably jQuery) to be able to do this. However my knowledge of using jQuery and using jQuery inside MVC4 Razor view is very limited so I seek guidance.
I modified my @Url.Action("Edit"..) like so :
<a href="@Url.Action("EditDocumentName",
new { @onclick="UpdatDocumentName(Model.Page.PageID);"})" >Edit</a>
and added this little script:
<script>
function UpdatDocumentName(id)
{
alert(id);
}
</script>
I know it's not even near to accomplish my task, but I wasn't even sure if I will be able to pass values to a JS function like so. But since it seems that there's no problem I plan to modify my function to take two parameters :
function UpdatDocumentName(PageId, DocId)
and inside the function to take the value of the textbox.
My question is, how having those values inside my JS function I can send them to my Edit Action in Page controller?
P.S
what I try to achieve is to allow the user to update a certain property of an entity which is part of List of entities rendered on my view. To be more descriptive here is what my view looks like (kind of):

which is generated like this:
@for (int j = 0; j < Model.Page.Documents.Count; j++ )
{
<tr>
<td>
@Html.TextBoxFor(m => m.Page.Documents[j].Name, new { id = Model.Page.Documents[j].DocumentID})
</td>
//more properties displayed...
If I am to use form to submit the change I have to wrap each @Html.TextBoxFor(m => m.Page.Documents[j].Name in a form, which I'm not sure is the best approach. But I might be wrong.
There is also icon for Update next to the Delete icon in Delete header but I've missed to show it.