I am trying to extract data from a ViewBag and paste it into a hidden form field via JS before submitting.
This does not work.
During debugging, I found that part of the JS expression is ignored, and as a result, "var" evaluates to an empty string.
Here is the part of JS that should perform the assignment:
function setid() {
var id = '@(ViewBag.id)';
$('#idField').val(id);
};
in debug I get the following expression, which of course results in a null identifier:
function setid() {
var id = '';
$('#idField').val(id);
};
(I'm not sure this is the only obstacle)
This JS function is called by the argument 'OnBegin' 'Ajax.BeginForm' on the same page.
This is a hidden html hidden field that is in the form I'm trying to assign an id value to:
input type ="hidden" name ="id" id ="idField" value =""
and the next is a controller that returns Partial, which is displayed as a jquery dialog:
public ActionResult openDialog()
{
ViewBag.id = TempData["id"];
return PartialView("EndLoadDetailsDialog");
}
:
, . , , :
, viewbag, , , .
JQuery. , , , . ( ) viewbag JS . , viewbag, , viewbag.
? viewbag ?