I am saving "Instruction" in CreateInstruction view. This view has partial view "CreateInstnAttribute" which saves "Attributes" related to this Instruction. It requires the InstnID as foreign key. The Instruction is saved using JQuery to avoid postback. So how can I get the InstnID to save the InstnAttribute? I tried HiddenField to save InstnId but I am not able to receive the value there. Can we use viewdata directly in JQuery? Any help will be appreciable.
4 Answers
You need to pass the InstId in the PartialView and access it inside the PartialView. The best way to is to create a AttributeViewModel (which would contain the InstID) and pass it down the partial view.
jQuery can access it using inline code as :
var InstID = "<%= Model.InstID %>"
//make the jQuery postback call here using InstID
Comments
All my PartialViews like the one you are talking follow the same base:
they come up a little more complex, but that was the base I started with, and you will get everything work in no time!