Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign Model property value from JavaScript value

I have a model with the following definition:

namespace ESimSolChemical.Models
{

    public class Employee
    {        
        public int EmployeeID{ get; set; }
        public string EmployeeName{ get; set; }
        public string Age{ get; set; }
        public string Address{ get; set; }

    }

I have Following JavaScript:

<script type="text/javascript">
    $(function () {
        $('#btnEmployeePiker').click(function () {
            var oParameter = new Object();
            oParameter.MultipleReturn = false;
            var oReturnObject = window.showModalDialog('/Employee/EmployeePiker/', oParameter, 'dialogHeight:470px;dialogWidth:550px;dialogLeft:400;dialogTop:100;center:yes;resizable:no;status:no;scroll:no');           
        });
    });
</script>

My Javascript oReturnObject contains two property Like :

oReturnObject.EmployeeID;
oReturnObject.EmployeeName;

Now I would like to assign:

@Model.employeeID=  oReturnObject.EmployeeID;

How can I accomplish this task?

like image 527
csefaruk Avatar asked Aug 08 '12 06:08

csefaruk


1 Answers

You cannot set server side values with Javascript. You could bind these values to input fields like textboxes or hidden fields and then use Javascript to modify these values of these input fields.

Take a look at these articles, it might help you out:

  • Setting property on the model object?
  • get value from @Model inside jquery script
like image 82
Brendan Vogt Avatar answered Oct 26 '22 07:10

Brendan Vogt