After submitting dropdownlist there is an error MVC
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a dropdownlist, after submitting there is an error http://prntscr.com/lnagi8
This is the View
@Html.DropDownListFor(m => m.SelectedAgrBall, Model.agrBall)
<input type="submit" value="save" />
and this is Controller (Post)
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View();
}
What should i do?
Controller
public ActionResult Main()
{
aspregistrationEntities1 obj = new aspregistrationEntities1();
List<agrBal> aggrBad = obj.agrBals.ToList();
List<agrBReceiv> aggrRec = obj.agrBReceivs.ToList();
SortedSet<string> org = new SortedSet<string>();
List<SelectListItem> items = new List<SelectListItem>();
Dictionary<int, string> orgNames = new Dictionary<int, string>();
foreach (agrBal tmp in aggrBad)
{
org.Add(tmp.ORG.ToString());
}
foreach(agrBReceiv tmp in aggrRec)
{
orgNames.Add(int.Parse(tmp.PBS.ToString()), tmp.KBO_RU.ToString());
}
//Drop organisations in dropdownlist
var types = new List<SelectListItem>();
foreach (string tmp in org)
{
string s = tmp+" - "+orgNames[int.Parse(tmp)];
SelectListItem item1 = new SelectListItem() { Text = s, Value = tmp.ToString() };
items.Add(item1);
}
Organisations m = new Organisations() {
agrBall= items
};
return View(m);
}
Model
{
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public string SelectedAgrBall { get; set; }
}
}
c# asp.net-mvc drop-down-menu
|
show 7 more comments
I have a dropdownlist, after submitting there is an error http://prntscr.com/lnagi8
This is the View
@Html.DropDownListFor(m => m.SelectedAgrBall, Model.agrBall)
<input type="submit" value="save" />
and this is Controller (Post)
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View();
}
What should i do?
Controller
public ActionResult Main()
{
aspregistrationEntities1 obj = new aspregistrationEntities1();
List<agrBal> aggrBad = obj.agrBals.ToList();
List<agrBReceiv> aggrRec = obj.agrBReceivs.ToList();
SortedSet<string> org = new SortedSet<string>();
List<SelectListItem> items = new List<SelectListItem>();
Dictionary<int, string> orgNames = new Dictionary<int, string>();
foreach (agrBal tmp in aggrBad)
{
org.Add(tmp.ORG.ToString());
}
foreach(agrBReceiv tmp in aggrRec)
{
orgNames.Add(int.Parse(tmp.PBS.ToString()), tmp.KBO_RU.ToString());
}
//Drop organisations in dropdownlist
var types = new List<SelectListItem>();
foreach (string tmp in org)
{
string s = tmp+" - "+orgNames[int.Parse(tmp)];
SelectListItem item1 = new SelectListItem() { Text = s, Value = tmp.ToString() };
items.Add(item1);
}
Organisations m = new Organisations() {
agrBall= items
};
return View(m);
}
Model
{
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public string SelectedAgrBall { get; set; }
}
}
c# asp.net-mvc drop-down-menu
what is Model.agrBall ? Unless it's a collection of select list items, you will probably need to modify your DropDownListFor line
– Broom
Nov 26 '18 at 19:45
And the error looks to be on the page render, not the submit
– Broom
Nov 26 '18 at 19:47
If you post your model class, as well as your HttpGet controller method, I might be able to help
– Broom
Nov 26 '18 at 19:48
"public List<SelectListItem> agrBall { get; set; }" it is Model.agrBall there is info for dropdownlist.
– Giorgi Asanidze
Nov 26 '18 at 20:33
I have poster controller method.
– Giorgi Asanidze
Nov 26 '18 at 20:37
|
show 7 more comments
I have a dropdownlist, after submitting there is an error http://prntscr.com/lnagi8
This is the View
@Html.DropDownListFor(m => m.SelectedAgrBall, Model.agrBall)
<input type="submit" value="save" />
and this is Controller (Post)
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View();
}
What should i do?
Controller
public ActionResult Main()
{
aspregistrationEntities1 obj = new aspregistrationEntities1();
List<agrBal> aggrBad = obj.agrBals.ToList();
List<agrBReceiv> aggrRec = obj.agrBReceivs.ToList();
SortedSet<string> org = new SortedSet<string>();
List<SelectListItem> items = new List<SelectListItem>();
Dictionary<int, string> orgNames = new Dictionary<int, string>();
foreach (agrBal tmp in aggrBad)
{
org.Add(tmp.ORG.ToString());
}
foreach(agrBReceiv tmp in aggrRec)
{
orgNames.Add(int.Parse(tmp.PBS.ToString()), tmp.KBO_RU.ToString());
}
//Drop organisations in dropdownlist
var types = new List<SelectListItem>();
foreach (string tmp in org)
{
string s = tmp+" - "+orgNames[int.Parse(tmp)];
SelectListItem item1 = new SelectListItem() { Text = s, Value = tmp.ToString() };
items.Add(item1);
}
Organisations m = new Organisations() {
agrBall= items
};
return View(m);
}
Model
{
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public string SelectedAgrBall { get; set; }
}
}
c# asp.net-mvc drop-down-menu
I have a dropdownlist, after submitting there is an error http://prntscr.com/lnagi8
This is the View
@Html.DropDownListFor(m => m.SelectedAgrBall, Model.agrBall)
<input type="submit" value="save" />
and this is Controller (Post)
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View();
}
What should i do?
Controller
public ActionResult Main()
{
aspregistrationEntities1 obj = new aspregistrationEntities1();
List<agrBal> aggrBad = obj.agrBals.ToList();
List<agrBReceiv> aggrRec = obj.agrBReceivs.ToList();
SortedSet<string> org = new SortedSet<string>();
List<SelectListItem> items = new List<SelectListItem>();
Dictionary<int, string> orgNames = new Dictionary<int, string>();
foreach (agrBal tmp in aggrBad)
{
org.Add(tmp.ORG.ToString());
}
foreach(agrBReceiv tmp in aggrRec)
{
orgNames.Add(int.Parse(tmp.PBS.ToString()), tmp.KBO_RU.ToString());
}
//Drop organisations in dropdownlist
var types = new List<SelectListItem>();
foreach (string tmp in org)
{
string s = tmp+" - "+orgNames[int.Parse(tmp)];
SelectListItem item1 = new SelectListItem() { Text = s, Value = tmp.ToString() };
items.Add(item1);
}
Organisations m = new Organisations() {
agrBall= items
};
return View(m);
}
Model
{
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public string SelectedAgrBall { get; set; }
}
}
c# asp.net-mvc drop-down-menu
c# asp.net-mvc drop-down-menu
edited Nov 26 '18 at 20:50
marc_s
585k13011251272
585k13011251272
asked Nov 26 '18 at 19:38
Giorgi AsanidzeGiorgi Asanidze
63
63
what is Model.agrBall ? Unless it's a collection of select list items, you will probably need to modify your DropDownListFor line
– Broom
Nov 26 '18 at 19:45
And the error looks to be on the page render, not the submit
– Broom
Nov 26 '18 at 19:47
If you post your model class, as well as your HttpGet controller method, I might be able to help
– Broom
Nov 26 '18 at 19:48
"public List<SelectListItem> agrBall { get; set; }" it is Model.agrBall there is info for dropdownlist.
– Giorgi Asanidze
Nov 26 '18 at 20:33
I have poster controller method.
– Giorgi Asanidze
Nov 26 '18 at 20:37
|
show 7 more comments
what is Model.agrBall ? Unless it's a collection of select list items, you will probably need to modify your DropDownListFor line
– Broom
Nov 26 '18 at 19:45
And the error looks to be on the page render, not the submit
– Broom
Nov 26 '18 at 19:47
If you post your model class, as well as your HttpGet controller method, I might be able to help
– Broom
Nov 26 '18 at 19:48
"public List<SelectListItem> agrBall { get; set; }" it is Model.agrBall there is info for dropdownlist.
– Giorgi Asanidze
Nov 26 '18 at 20:33
I have poster controller method.
– Giorgi Asanidze
Nov 26 '18 at 20:37
what is Model.agrBall ? Unless it's a collection of select list items, you will probably need to modify your DropDownListFor line
– Broom
Nov 26 '18 at 19:45
what is Model.agrBall ? Unless it's a collection of select list items, you will probably need to modify your DropDownListFor line
– Broom
Nov 26 '18 at 19:45
And the error looks to be on the page render, not the submit
– Broom
Nov 26 '18 at 19:47
And the error looks to be on the page render, not the submit
– Broom
Nov 26 '18 at 19:47
If you post your model class, as well as your HttpGet controller method, I might be able to help
– Broom
Nov 26 '18 at 19:48
If you post your model class, as well as your HttpGet controller method, I might be able to help
– Broom
Nov 26 '18 at 19:48
"public List<SelectListItem> agrBall { get; set; }" it is Model.agrBall there is info for dropdownlist.
– Giorgi Asanidze
Nov 26 '18 at 20:33
"public List<SelectListItem> agrBall { get; set; }" it is Model.agrBall there is info for dropdownlist.
– Giorgi Asanidze
Nov 26 '18 at 20:33
I have poster controller method.
– Giorgi Asanidze
Nov 26 '18 at 20:37
I have poster controller method.
– Giorgi Asanidze
Nov 26 '18 at 20:37
|
show 7 more comments
2 Answers
2
active
oldest
votes
You return View without model on HttpPost action so null reference exception occurs because you're using Model object in Main.cshtml
You should pass the model object to view.
(I think) if your model is Organizations m
like that
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
add a comment |
Followed furkanhb and then modified the model/post method to allow for reloading of the page with a pre-selected value
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public SelectListItem SelectedAgrBall { get; set; }
}
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall.Value;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487896%2fafter-submitting-dropdownlist-there-is-an-error-mvc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You return View without model on HttpPost action so null reference exception occurs because you're using Model object in Main.cshtml
You should pass the model object to view.
(I think) if your model is Organizations m
like that
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
add a comment |
You return View without model on HttpPost action so null reference exception occurs because you're using Model object in Main.cshtml
You should pass the model object to view.
(I think) if your model is Organizations m
like that
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
add a comment |
You return View without model on HttpPost action so null reference exception occurs because you're using Model object in Main.cshtml
You should pass the model object to view.
(I think) if your model is Organizations m
like that
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
You return View without model on HttpPost action so null reference exception occurs because you're using Model object in Main.cshtml
You should pass the model object to view.
(I think) if your model is Organizations m
like that
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
answered Nov 26 '18 at 20:38
furkanhbfurkanhb
94
94
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
add a comment |
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
I change code like return View(m); and there is new error prntscr.com/lnbe4p.
– Giorgi Asanidze
Nov 26 '18 at 20:47
add a comment |
Followed furkanhb and then modified the model/post method to allow for reloading of the page with a pre-selected value
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public SelectListItem SelectedAgrBall { get; set; }
}
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall.Value;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
add a comment |
Followed furkanhb and then modified the model/post method to allow for reloading of the page with a pre-selected value
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public SelectListItem SelectedAgrBall { get; set; }
}
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall.Value;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
add a comment |
Followed furkanhb and then modified the model/post method to allow for reloading of the page with a pre-selected value
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public SelectListItem SelectedAgrBall { get; set; }
}
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall.Value;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
Followed furkanhb and then modified the model/post method to allow for reloading of the page with a pre-selected value
public class Organisations
{
public List<SelectListItem> agrBall { get; set; }
public SelectListItem SelectedAgrBall { get; set; }
}
[HttpPost]
public ActionResult Main(string Years, string Periods, Organisations m)
{
string s = m.SelectedAgrBall.Value;
int ss = int.Parse(s);
string t = Years;
string b = Periods;
return View(m);
}
answered Nov 26 '18 at 21:02
BroomBroom
460215
460215
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487896%2fafter-submitting-dropdownlist-there-is-an-error-mvc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is Model.agrBall ? Unless it's a collection of select list items, you will probably need to modify your DropDownListFor line
– Broom
Nov 26 '18 at 19:45
And the error looks to be on the page render, not the submit
– Broom
Nov 26 '18 at 19:47
If you post your model class, as well as your HttpGet controller method, I might be able to help
– Broom
Nov 26 '18 at 19:48
"public List<SelectListItem> agrBall { get; set; }" it is Model.agrBall there is info for dropdownlist.
– Giorgi Asanidze
Nov 26 '18 at 20:33
I have poster controller method.
– Giorgi Asanidze
Nov 26 '18 at 20:37