0

I have a quick question nothing to intense I hope.

In a crud template, when someone adds a new record into the database you can have an ajax form send the data off to the server then get redirected to the list of all the records in the database.

So the flow of events would be:

 ViewResult Edit => Edit Razor View => ActionResult Edit => ViewResult AllRecords => AllRecords Razor View

I know you can have JQuery animate the introduction of the new record into the list.

I'm guessing you need to pass the newly added item to the Controller then get the Controller to pass that information to JQuery but what would be in the razor view to do this kind of thing.

So basically how do you get JQuery to animate the introduction of the new record into the list?

1 Answer 1

1

If I understand correctly, you want to have the item shown in the list after it has been added, but without doing a redirect.

If this is the case, you have two options.

  1. When you submit the form and send the data to the controller's action method, you can either return JSON w/ the information on the new record, which would include the newly added Id. Then in the AJAX callback you would parse the returned JSON and feed it to some kind of template to populate the list.

  2. Or much easier would be to send the information to the controller's action method, and once the record is added, pass that new record to a Razor view that has been set up to specifically render one row. You then return this rendered HTML in the AJAX call back and simply insert it to the end of the list.

Approach #2 is easier, but is not very reusable.

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.