"razor: show editable list" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "razor: show editable list" answered properly. Developers are finding an appropriate answer about razor: show editable list related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like razor: show editable list. Enter your desired code related query in the search bar and get every piece of information about C# code related question on razor: show editable list.
razor: show editable list
// You need form tag in order for HttpPost. The trick is to either use for loop to generate
// correct Ids, or create Partial View.
// I like to use partial view, since it is a bit cleaner.
// For example
// ViewModel
public class SampleViewModel
{
public IList<IncidentListmodel> IncidentListmodel = new List<IncidentListmodel>();
}
// Model
public class IncidentListmodel
{
public int Id { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Note { get; set; }
}
// View
@model AspNetMvc.Models.SampleViewModel
@foreach (var item in Model.IncidentListmodel)
{
@Html.Partial("_UpdatePartial", item)
}
// Partial View (_UpdatePartial.cshtml)
@model AspNetMvc.Models.IncidentListmodel
@using (Html.BeginForm("Updateinc", "Home"))
{
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.Name)
@Html.DisplayFor(m => m.Name)
@Html.DisplayFor(m => m.Title)
@Html.TextAreaFor(m => m.Note, 2, 20, new { maxlength = 50 })
<button type="submit">Update</button>
}
// Controller
public class HomeController : Controller
{
public ActionResult Updateinc()
{
var model = new SampleViewModel
{
IncidentListmodel = new List<IncidentListmodel>
{
new IncidentListmodel {Id = 1, Name = "One", Note = "Sample text"},
new IncidentListmodel {Id = 2, Name = "Two"},
new IncidentListmodel {Id = 3, Name = "Three"},
}
};
return View(model);
}
[HttpPost]
public ActionResult Updateinc(IncidentListmodel viewModel)
{
// Rediret to different page.
return RedirectToAction("Index");
}
}
Source: stackoverflow.com
All those coders who are working on the C# based application and are stuck on razor: show editable list can get a collection of related answers to their query. Programmers need to enter their query on razor: show editable list related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about razor: show editable list for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of razor: show editable list while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "razor: show editable list". Visit this developer's friendly online web community, CodeProZone, and get your queries like razor: show editable list resolved professionally and stay updated to the latest C# updates.