Заголовок конечно не о чем, но кратно сложно сформулировать. Я хочу сохранять все данные от пользователя не в БД а например в Лист. Например: пользователь сохранил форму и все данные отправились в Лист и нас главной странице появилась запись, потом вторая и т.д. Когда аппликация рестартуется, то все пропадает. Create.cshtml
@using (Html.BeginForm())
{
<div class="form-horizontal">
<h4>Create New System</h4>
<hr />
<table>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.sys_id)</td>
<td>
@Html.EditorFor(model => model.sys_id)
@Html.ValidationMessageFor(model => model.sys_id)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.sys_name)</td>
<td>
@Html.EditorFor(model => model.sys_name)
@Html.ValidationMessageFor(model => model.sys_name)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.sys_valid)</td>
<td>
@Html.EditorFor(model => model.sys_valid)
@Html.ValidationMessageFor(model => model.sys_valid)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.sys_deleted)</td>
<td>
@Html.EditorFor(model => model.sys_deleted)
@Html.ValidationMessageFor(model => model.sys_deleted)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.sys_location)</td>
<td>
@Html.EditorFor(model => model.sys_location)
@Html.ValidationMessageFor(model => model.sys_location)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.connection)</td>
<td>
@Html.EditorFor(model => model.connection)
@Html.ValidationMessageFor(model => model.connection)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.sys_type)</td>
<td>
@Html.EditorFor(model => model.sys_type)
@Html.ValidationMessageFor(model => model.sys_type)
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(model => model.category_authorization)</td>
<td>
@Html.EditorFor(model => model.category_authorization)
@Html.ValidationMessageFor(model => model.category_authorization)
</td>
</tr>
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
<input type="button" value="Cancel" class="btn btn-default" onclick="window.location.href='@Url.Action("Index")'" />
</div>
</div>
</div>
}
Controller
public class SystemsController : Controller
{
List<SystemViewModel> model = new List<SystemViewModel>() { };
public ActionResult Index()
{
return this.View(model);
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(SystemViewModel systemModel)
{
SystemViewModel newModel = new SystemViewModel()
{
sys_id = systemModel.sys_id,
sys_name = systemModel.sys_name,
sys_valid = systemModel.sys_valid,
sys_deleted = systemModel.sys_deleted,
sys_location = systemModel.sys_location,
connection = systemModel.connection,
sys_type = systemModel.sys_type,
category_authorization = systemModel.category_authorization
};
model.Add(newModel);
return RedirectToAction("Index");
}
}
Model
public class SystemViewModel
{
public long sys_id { get; set; } = 1;
[DisplayName("System")]
public string sys_name { get; set; }
public string sys_valid { get; set; }
public DateTime? sys_deleted { get; set; }
public string sys_location { get; set; }
public string connection { get; set; }
public string sys_type { get; set; }
public bool category_authorization { get; set; }
}
Index.cshtml
@using (this.Html.BeginForm())
{
<table>
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>IsValid</th>
<th>Deleted</th>
<th>Location</th>
<th>Connection</th>
<th>Type</th>
<th>HasCategoryAuthorization</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
foreach (var s in Model)
{
<tr title="Edit" data-link="@Url.Action("Edit", new { sys_id = s.sys_id })">
<td class="centered"><p>@s.sys_id</p></td>
<td class="centered"><p>@s.sys_name</p></td>
<td class="centered"><p>@s.sys_valid</p></td>
<td class="centered"><p>@s.sys_deleted</p></td>
<td class="centered"><p>@s.sys_location</p></td>
<td class="centered"><p>@s.connection</p></td>
<td class="centered"><p>@s.sys_type</p></td>
<td class="centered"><p>@s.category_authorization</p></td>
</tr>
}
}
</tbody>
</table>
}
List<>
объект? Или как это?