Skip to content
Loading
Undefined in ID column  
  •                             class="form-group">  
  •                                 @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-3" })  
  •                                 class="col-md-9">  
  •                                     @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control",@Value=Model.Description} })  
  •   
  •                                     @Html.ValidationMessageFor(model => model.Description, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •                             class="form-group">  
  •                                 @Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-3" })  
  •                                 class="col-md-2">  
  •                                     @Html.CheckBoxFor(model => model.IsActive, new { @checked = (Model.IsActive == true ? "checked" : "") })  
  •   
  •                                     @Html.ValidationMessageFor(model => model.IsActive, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •                           
  •                   
  •                   
  •                 class="modal-footer">  
  •                     "button" class="btn btn-secondary" data-dismiss="modal">Cancel  
  •                     "submit" class="btn btn-primary">Save Changes  
  •                   
  •               
  •           
  •       
  • }  
  • +1
  • Hi Sachin
     
       I want when i click on Add ID Textbox should be blank . It shows undefined
     
    Thanks 
    +1
  • Sachin Singh
    If Id is null then you are passing an empty Location object to the view , for adding location, as the Location object is null so the Id is null that is the reason it is saying the value as null.
     
    In case of edit when you are passing a filled Location object then again in the view the value attribute is not assigned anywhere, so it will always be null.
     If you want a value then it should be
    1. @Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control", @Value=Model.Id} })  
     
    +1
  • HI

     

      Below is the Controler thru which i am calling

    [HttpGet]

    public ActionResult CreateEdit(string Id)

    {

    if (String.IsNullOrEmpty(Id))

    {

    return PartialView("_CreateEdit", new Location());

    }

    else

    {

    return PartialView("_CreateEdit", dbLocation.GetById(Id));

    }

    }

    *****************************

    Thanks 

    +1
  • Sachin Singh

    are you passing the model into this partial view?

     

    1. public ActionResult EditPartial()  
    2. {  
    3.   
    4. return PartialView(new Location());  
    5. }  

    if it is statically called then also you need to pass the model

    1. @Html.Partial("_EditPartial", Model.Location);  

    if it is a view then make sure you are passing the model from the controller to view

    1. public ActionResult Index()  
    2. {  
    3.   
    4. return View(new Location());  
    5. }  

     if you have another issue like ModelState.IsValid is false then let me know.

    +1