2
I can not carry out enumerate, I switched to another reception of information in the View but I do not know how to correct, I checked other forms in Stackoverflow but I did not understand.
Model:
namespace WebApplication4.Models
{
public class modelExemplo
{
public StringBuilder lista { get; set; } = new StringBuilder();
}
}
Controller:
namespace WebApplication4.Controllers{
public ActionResult funcaodeteste()
{
modelExemplo obj = new modelExemplo();
obj.listNewsletter.AppendLine("teste1");
obj.listNewsletter.AppendLine("teste2");
return View(obj);
}
}
View:
@model IEnumerable<WebApplication4.Models.modelExemplo>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Download</title>
</head>
<body>
@foreach (var item in Model) {
<p>item</p>
}
</body>
</html>
Why you declared Stringbuilder inside your builder ?
– Dev
Because I need to instantiate the Stringbuilder object in order to use it because if I try to insert and have not instantiated it will give Nullreference
– rock.ownar
Instantiate yes, but do not define it within the same...
– Dev
@Matheus, there is another way because unknown, that is not inside a constructor is an instance in the attribute, I could do so too: public Stringbuilder list { get; set; } public modelExemplo(){ list = new Stringbuilder; }
– rock.ownar
My mistake... disregard
– Dev
@Matheus no problem, rs
– rock.ownar