Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Please help urgent , Value is not coming into the post action from the model

$
0
0

My Model class

 public class WeatherVM
    {
        public int LocationId { get; set; }
        public DateTime ForcastDate { get; set; }
        public WeatherLocation WeatherLocation;
        public IEnumerable<Weather> Weather { get; set; }
        public IEnumerable<SelectListItem> Locations { get; set; }

    }

public class WeatherLocation
    {
        [Key]
        public int LocationId { get; set; }
        [Required]
        public string LocationName { get; set; }
        [Required]
        public string Woeid { get; set; }
    }

View

@model MetaWeather.ViewModels.WeatherVM
@{
    ViewData["Title"] = "Index";
}<h1>Forcast Weather </h1><form asp-controller="Forcast" asp-action="Index" method="post"><div class="form-group"><div class="row"><div class="col-sm-2"><label asp-for="Locations">Locations</label></div><div class="col-4">
                @Html.DropDownListFor(m => m.WeatherLocation.LocationId, Model.Locations, "-Select a Location",
                new { @class = "form-control" })<span asp-validation-for="WeatherLocation.LocationId" class="text-danger"></span></div></div></div><div class="form-group row"><div class="col-sm-2"><label asp-for="ForcastDate"></label></div><div class="col-4"><input type='text' id="forcastDate" asp-for="ForcastDate" class="form-control" /><span asp-validation-for="ForcastDate" class="text-danger"></span></div><br /><input type="submit" value="Save" class="btn-sm btn btn-primary" /></div><div class="form-group row"><div class="col-4 offset-4"><button type="submit" class="btn btn-primary form-control"> View</button></div></div></form>
@section Scripts{<script>$(document).ready(function () {$("#forcastDate").datepicker({ format: 'dd/mm/yyyy', date: new Date(1900, 01, 01), autoclose: true, todayBtn: 'linked' });

        });
    </script>
}

Controller

 [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Index(WeatherVM weatherVM) // Selected Region is not coming here. How can I pass Location Id
        {
            return View();
        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>