❔ how To create a view that can accept range of inputs, for models range for DbSet.AddRange method
This is my View Model where i am sending an Ienumarable of Model Option to get range of option for the question
22 Replies
this is my controller method to pass ViewModel
What do you mean? Just
@model OnlineExam.Models.ViewModels.OptionsVM
@{
ViewData["Title"] = "Edit";
}
<h1>Question Edit</h1>
<form method="post">
<div class="container">
<div class="row">
<h4>Edit Question or Add Options</h4>
</div>
</div>
<div>
<label asp-for="question.question">Question</label>
<input asp-for="question.question" />
<span asp-validation-for="question.question"></span>
</div>
@foreach(var obj in Model.OptionsList)
{
<div>
<label asp-for="@obj.option"></label>
<input asp-for="@obj.option" disabled/>
</div>
}
@<div>
<label asp-for="OptionsList"></label>
<input asp-for="@obj.option" />
</div>
<div>
<label asp-for="@obj.option"></label>
<input asp-for="@obj.option" disabled />
</div>@
<button type="submit" class="btn btn-primary">Update</button>
<a asp-controller="Question" asp-action="Index">Go Back</a>
</form> this my view
</form> this my view
Yeah
And what doesn't work about it?
Ah, wait, the issue is with how to create the form?
So that it sends multiple fields to the controller?
yes
Might need to name those fields manually
That is,
and you should be able to get it with
no no please come to coice chat
*voice
i will share my screen
I can't right now, sorry
ok wait
GitHub
GitHub - digvijay-ship-it/Online-Exam
Contribute to digvijay-ship-it/Online-Exam development by creating an account on GitHub.
this my project repo
what i am trying to do is adding 4 input fields in view
Then add those 4 input fields
to take Input for Model Option's option(which Is a property)
Well, did you try the way I posted?
Angius#1586
That is,
and you should be able to get it with
Quoted by
React with ❌ to remove this embed.
With naming them manually?
Ah, wait, I think I can see the issue...
Each answer has its own ID and stuff, so just sending a list of strings won't do
yes
thats why i added Option as Ienumarable<Option> in ViewModel
that option is connected to Question Model vie FK
Unless, perhaps,
Also, as a side note, line 59 of
QuestionsController
id
cannot be both null
and 0
at the same time
In any case, try the dictionary
If that fails, I'm out of ideas, sorrysorry i shuld have put ||
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.