show only the date in @Html.EditorFor helper

[DataType(DataType.Date, ErrorMessage="Date only")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? YearBought { get; set; }


https://stackoverflow.com/questions/33247295/show-only-the-date-in-html-editorfor-helper
Advertisements

url.action with query string in razor view

<script type="text/javascript">
   var src = "@Html.Raw(Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 }))";
   $(document.createElement("img")).attr("src", src);
</script>


https://stackoverflow.com/questions/5872157/mvc3-url-action-querystring-generation

Populating data in a viewmodel from database

public ActionResult ListPeople()
{
    var model = (from p in db.Persons // .Includes("Addresses") here?
                select new PersonAddViewModel() {
                    Id = p.Id,
                    Name = p.Name,
                    Street = p.Address.Street,
                    // or if collection
                    Street2 = p.Addresses.Select(a => a.Street).FirstOrDefault()
                });

    return View(model.ToList());
}


https://stackoverflow.com/questions/16071531/mvc4-c-sharp-populating-data-in-a-viewmodel-from-database
https://stackoverflow.com/questions/36628107/how-to-populate-a-list-inside-my-viewmodel-from-database
https://stackoverflow.com/questions/24951677/populating-a-viewmodel-from-a-database-model

RedirectToAction with querystring

return RedirectToAction("Index", "Customer", new { id = custId }); https://forums.asp.net/t/1202550.aspx?RedirectToAction+with+querystring+ https://stackoverflow.com/questions/40509369/asp-net-mvc-add-query-string-value-to-redirecttoaction-in-controller https://stackoverflow.com/questions/31343865/how-to-add-querystring-values-with-redirecttoaction-method-that-is-pointing-to-a