1

I have used jQuery to display info for a record depending on some user selections. I need to add a button or a link that will take them to an Edit view, but don't know the best way to achieve this. The ID for the navigation will change as they browse the data.

Can I dynamically alter the ActionLink using jQuery?

More info Users make a selection from list boxes, then I go and get the appropriate data via a $.getJSON call. Information is then displayed in a summary box with the option to edit the data. So the fetch looks like this

$.getJSON("/Result/FetchState", { metricId: metId, calendarId: calId }, function (data) {
              $('#Info1').val(data.ResultId);
              $('#Info3').val(data.Headline);
              if (data.AllowEdit) { $('#btnEdit').attr('disabled', false); } else { $('#btnEdit').attr('disabled', true); }
              $('#editlink').val(data.ResultId);
          });

I now need to be able to navigate to a View (/Result/Edit/{id}) where {id} is the ResultId from the FetchState call.

3
  • You can use jQuery to alter the href of the link that ActionLink has generated yes. This might be a bit brittle if the path to the application or the view changes in future. My gut feeling is to pass an edit link to the view rather than try and generate one. Perhaps you could hide it by default and just use jQuery to display it. Commented Jul 19, 2011 at 11:11
  • A bit more detail (and some code) would help give you a better answer. Commented Jul 19, 2011 at 11:12
  • Yeah, I don't like the idea of altering the href directly. All I really need to do is inject an Id into the Url. Commented Jul 19, 2011 at 12:44

1 Answer 1

1

You could use a <form> containing a hidden field and a submit button. When the user performs some selection you would set the value of the hidden field to this new selection:

$('#SomeHiddenField').val('some new value');

Then when the user submits the button this will redirect to the new action passing along the value of the hidden field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.