razor: show editable list
C#
// 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");
}
}
Also in C#:
- Title
- string to enum c# 3
- Category
- C#
- Title
- unity monobehaviour
- Category
- C#
- Title
- error CS0542
- Category
- C#
- Title
- how to get odd saturday in a month in c#
- Category
- C#
- Title
- print gridcontrol devexpress
- Category
- C#
- Title
- divide string in chunks c#
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- unity how to change text in script
- Category
- C#
- Title
- unity ui change sprite
- Category
- C#
- Title
- while loop check condition c#
- Category
- C#
- Title
- c# catch two exceptions in one block
- Category
- C#
- Title
- dynamically add rows to datagridview c#
- Category
- C#
- Title
- first sentence letter capital in c#
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- c# getter setter
- Category
- C#
- Title
- how to generate random unique id in c#
- Category
- C#
- Title
- c# storing value in session
- Category
- C#
- Title
- unity variable from another script
- Category
- C#
- Title
- c# convert double to int
- Category
- C#
- Title
- unity custom editor save changes
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- unity check when clicked on object
- Category
- C#
- Title
- convert array object to int[] c#
- Category
- C#
- Title
- c# list all files in a directory and subdirectory
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- ihttpactionresult to object c#
- Category
- C#
- Title
- how to name GameObject in c#
- Category
- C#
- Title
- unity c# get bool from another script
- Category
- C#
- Title
- how to deactivate objects through scripts in unity
- Category
- C#
- Title
- how to redirect to extern page in .net core
- Category
- C#
- Title
- winforms c# add data to datagridview with a button
- Category
- C#
- Title
- how to do a messagebox in c#
- Category
- C#
- Title
- c# declare an int list
- Category
- C#
- Title
- how to copy one array value to another without reference c#
- Category
- C#
- Title
- how to get component in unity c#
- Category
- C#
- Title
- unity how to change rotation
- Category
- C#
- Title
- or in unity
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- cannot convert string to generic type c#
- Category
- C#
- Title
- C# save pdf stream to file
- Category
- C#
- Title
- unity movetowards 2d
- Category
- C#
- Title
- return random from enum
- Category
- C#
- Title
- unity instantiate vector3
- Category
- C#
- Title
- unity change text
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- unity custom update
- Category
- C#
- Title
- c# tab character
- Category
- C#
- Title
- order by C#
- Category
- C#
- Title
- unity get all by tag
- Category
- C#
- Title
- list with two values c#
- Category
- C#
- Title
- transform.Translate movement
- Category
- C#
- Title
- unity switch to scene and transfer data
- Category
- C#
- Title
- vector between two points unity
- Category
- C#
- Title
- vector3.lerp
- Category
- C#
- Title
- how do i foreach c#
- Category
- C#
- Title
- C# loop through array of objet
- Category
- C#
- Title
- how to use K2 games Games parallax background
- Category
- C#
- Title
- unity onclick addlistener
- Category
- C#
- Title
- POST http://localhost:5001/api/v1/identity/login 500 (Internal Server Error) LoginForm.jsx:39 Error: Request failed with status code 500 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:61)
- Category
- C#
- Title
- change partial view based on select asp.net core
- Category
- C#
- Title
- how to reference a transform unity
- Category
- C#
- Title
- c# find duplicates in list of strings
- Category
- C#
- Title
- c# list remove item based on property duplicate
- Category
- C#
- Title
- how to destroy a gameobject after some hits in unity 3d
- Category
- C#
- Title
- format float to time c#
- Category
- C#
- Title
- using serial port in c#
- Category
- C#
- Title
- c# array Reverse method
- Category
- C#
- Title
- C# invoke
- Category
- C#
- Title
- while loop in c#
- Category
- C#
- Title
- httpclient soap request c#
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- how to instantiate a gameobject
- Category
- C#
- Title
- IEnumerator
- Category
- C#
- Title
- what is the or symbol in C#
- Category
- C#
- Title
- increase variable C#
- Category
- C#
- Title
- or symbol in unity
- Category
- C#
- Title
- c# string to datetime
- Category
- C#
- Title
- how to add to a list c#
- Category
- C#
- Title
- change label text size wpf C#
- Category
- C#
- Title
- remove items from list c# condition
- Category
- C#
- Title
- c# get object property value by name
- Category
- C#
- Title
- xamarin forms alarm
- Category
- C#
- Title
- c# write variable in string
- Category
- C#
- Title
- get last element of array c#
- Category
- C#
- Title
- create char array c#
- Category
- C#
- Title
- hwo to make an array in C#
- Category
- C#
- Title
- c# unhandled exception in thread
- Category
- C#
- Title
- c# how to delete a file
- Category
- C#
- Title
- c# get gridview DataKeyNames
- Category
- C#
- Title
- how to crouch in unity
- Category
- C#
- Title
- percentage in c#
- Category
- C#
- Title
- rotate to face direction
- Category
- C#
- Title
- docker ssh
- Category
- C#
- Title
- c# remove from list in foreach
- Category
- C#
- Title
- .net loop through dictionary
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- wpf use enum description
- Category
- C#
- Title
- c# anonymous class
- Category
- C#
- Title
- array to list C
- Category
- C#
- Title
- random from list c#
- Category
- C#